Being a relatively new user of crystal I thought I was making progress. Managed to get all my reports working correctly - then discovered during my testing that one report is presenting false data (or data that was there previously). Using VB6 and crystal 8.5 I created the report and load the report initially with data from an Access 2000 database using the SQL statement below. This works fine the first time round.
SELECT Sum(manhours.Manhours) AS SumYearHours, Company.Company
FROM manhours INNER JOIN Company ON manhours.CompanyID = Company.CompanyID
WHERE (((manhours.RptDate)>0))
GROUP BY Company.Company, manhours.CompanyID;
This VB code segment loads the initial data
Private Sub LoadHoursReport()
HoursReport.DiscardSavedData
CRVReport.EnableGroupTree = False
HoursReport.txtHours.SetText "TOTAL HOURS WORKED"
CRVReport.ReportSource = HoursReport
HoursReport.CompanyName.SetText CompanyName
HoursReport.PaperSize = crPaperA4
CRVReport.ViewReport
CRVReport.Zoom 1
Screen.MousePointer = vbDefault
End Sub
I then have a couple of Date Time Pickers that allow me to refine the dates of the the query - this works fine all the time - VB code used is below:
My only problem is that if I select a date range - the report displays the data correctly and then I return to my normal application doing something else. If I open this same report up again it presents the same data that was there before I closed the report. ie it does not seem to want to display all my data as per my SQL statement above. I thought the 'DiscardSavedData' statements got rid of previous data. If I restart my application then the correct data is presented first time. Can someone help me please.
Case 13 'Manhours
sDate = "#" & Format((DTShowEndDate.Value + 1), "mm/dd/yyyy" & "#"
If CRVReport.IsBusy Then Exit Sub
Screen.MousePointer = vbHourglass
DTShowStartDate.Enabled = False
DTShowEndDate.Enabled = False
cboListing.Enabled = False
HoursReport.IsNoData = False
HoursReport.txtHours.SetText "PERIOD " & Format$(DTShowStartDate.Value, "dd/mm/yyyy" & _
" TO " & Format$(DTShowEndDate.Value, "dd/mm/yyyy"
SQL = "SELECT Sum(manhours.Manhours) AS SumYearHours, Company.Company" & _
" FROM manhours INNER JOIN Company ON manhours.CompanyID =" & _
" Company.CompanyID WHERE (((manhours.rptDate) >= #" & Format(DTShowStartDate, "mm/dd/yyyy" & "#" & _
" AND (Manhours.rptDate) <" & sDate & ")" & _
" GROUP BY Company.Company, manhours.CompanyID"
'Debug.Print SQL
rsadoReport.Open SQL, Con, adOpenDynamic, adLockBatchOptimistic
HoursReport.DiscardSavedData
HoursReport.Database.SetDataSource rsadoReport
If CRVReport.Visible Then
HoursReport.ReadRecords
CRVReport.Refresh
End If
DTShowStartDate.Enabled = True
DTShowEndDate.Enabled = True
cboListing.Enabled = True
End Select
Screen.MousePointer = vbDefault
End Sub
SELECT Sum(manhours.Manhours) AS SumYearHours, Company.Company
FROM manhours INNER JOIN Company ON manhours.CompanyID = Company.CompanyID
WHERE (((manhours.RptDate)>0))
GROUP BY Company.Company, manhours.CompanyID;
This VB code segment loads the initial data
Private Sub LoadHoursReport()
HoursReport.DiscardSavedData
CRVReport.EnableGroupTree = False
HoursReport.txtHours.SetText "TOTAL HOURS WORKED"
CRVReport.ReportSource = HoursReport
HoursReport.CompanyName.SetText CompanyName
HoursReport.PaperSize = crPaperA4
CRVReport.ViewReport
CRVReport.Zoom 1
Screen.MousePointer = vbDefault
End Sub
I then have a couple of Date Time Pickers that allow me to refine the dates of the the query - this works fine all the time - VB code used is below:
My only problem is that if I select a date range - the report displays the data correctly and then I return to my normal application doing something else. If I open this same report up again it presents the same data that was there before I closed the report. ie it does not seem to want to display all my data as per my SQL statement above. I thought the 'DiscardSavedData' statements got rid of previous data. If I restart my application then the correct data is presented first time. Can someone help me please.
Case 13 'Manhours
sDate = "#" & Format((DTShowEndDate.Value + 1), "mm/dd/yyyy" & "#"
If CRVReport.IsBusy Then Exit Sub
Screen.MousePointer = vbHourglass
DTShowStartDate.Enabled = False
DTShowEndDate.Enabled = False
cboListing.Enabled = False
HoursReport.IsNoData = False
HoursReport.txtHours.SetText "PERIOD " & Format$(DTShowStartDate.Value, "dd/mm/yyyy" & _
" TO " & Format$(DTShowEndDate.Value, "dd/mm/yyyy"
SQL = "SELECT Sum(manhours.Manhours) AS SumYearHours, Company.Company" & _
" FROM manhours INNER JOIN Company ON manhours.CompanyID =" & _
" Company.CompanyID WHERE (((manhours.rptDate) >= #" & Format(DTShowStartDate, "mm/dd/yyyy" & "#" & _
" AND (Manhours.rptDate) <" & sDate & ")" & _
" GROUP BY Company.Company, manhours.CompanyID"
'Debug.Print SQL
rsadoReport.Open SQL, Con, adOpenDynamic, adLockBatchOptimistic
HoursReport.DiscardSavedData
HoursReport.Database.SetDataSource rsadoReport
If CRVReport.Visible Then
HoursReport.ReadRecords
CRVReport.Refresh
End If
DTShowStartDate.Enabled = True
DTShowEndDate.Enabled = True
cboListing.Enabled = True
End Select
Screen.MousePointer = vbDefault
End Sub