Beaner5434
Programmer
I have developed a VB5 app which uses a .dsr report and the CRViewer. The user has the option of selecting two dates to compare on the VB5 form, then printing the results via the .DSR report. The following code is used when opening the form that contains the CRViewer control:
-------------------------------------------------
Option Explicit
Dim Report As New rptDooley
Dim DAOSnap As DAO.Recordset
Dim DAODb As DAO.Database
Dim wrkJet As Workspace
Private Sub Form_Load()
Dim sForm As String
Screen.MousePointer = vbHourglass
' Create a Microsoft Jet workspace
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
' Set the location of the database here
Set DAODb = wrkJet.OpenDatabase(dbMerger)
' Create the recordset off the designated Date fields,
sForm = "SELECT DooleyTemp.* From DooleyTemp "
sForm = sForm & "ORDER BY DooleyTemp.SummaryGroup;"
Set DAOSnap = DAODb.OpenRecordset(sForm)
Report.Database.SetDataSource DAOSnap
Report.ReadRecords
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set wrkJet = Nothing
Set DAODb = Nothing
Set DAOSnap = Nothing
Report.DiscardSavedData
Set Report = Nothing
End Sub
-------------------------------------------------
When I click the report button on the dialog form, it opens the report and shows the last data set displayed. If I then simply close the report form and reopen it, it shows the data the user has selected. I've tried putting the Report.DiscardSavedData at the start of the Form_Load event, after the report has been displayed, and when the form is closed, but it makes no difference; I have to open, close, and then reopen the report in order to display the information I want. I know it has to be something simple, but I am clueless at this point, and I am hoping one of you can help me out with this little glitch.
TIA for your assistance!
-------------------------------------------------
Option Explicit
Dim Report As New rptDooley
Dim DAOSnap As DAO.Recordset
Dim DAODb As DAO.Database
Dim wrkJet As Workspace
Private Sub Form_Load()
Dim sForm As String
Screen.MousePointer = vbHourglass
' Create a Microsoft Jet workspace
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
' Set the location of the database here
Set DAODb = wrkJet.OpenDatabase(dbMerger)
' Create the recordset off the designated Date fields,
sForm = "SELECT DooleyTemp.* From DooleyTemp "
sForm = sForm & "ORDER BY DooleyTemp.SummaryGroup;"
Set DAOSnap = DAODb.OpenRecordset(sForm)
Report.Database.SetDataSource DAOSnap
Report.ReadRecords
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set wrkJet = Nothing
Set DAODb = Nothing
Set DAOSnap = Nothing
Report.DiscardSavedData
Set Report = Nothing
End Sub
-------------------------------------------------
When I click the report button on the dialog form, it opens the report and shows the last data set displayed. If I then simply close the report form and reopen it, it shows the data the user has selected. I've tried putting the Report.DiscardSavedData at the start of the Form_Load event, after the report has been displayed, and when the form is closed, but it makes no difference; I have to open, close, and then reopen the report in order to display the information I want. I know it has to be something simple, but I am clueless at this point, and I am hoping one of you can help me out with this little glitch.
TIA for your assistance!