A2003 on WinXP
I'm in a situation where I need to open a recordset named "summset" when a report opens, in a Group1_Print event I need to save records with summary totals to an existing table "CommSumm", then when the report closes I need to close my recordset. I need this opened recordset ("summset") available in all areas of the report. I did make my varitable a public variable at the report level:
public summset as dao.recordset
I was putting my recordset open in my Report_Activate event but it is not getting fired before the Group1_Print event. Then I put my recordset close in my Report_Deactivate event.
Which events do I open my recordset and close my recordset in?
You see, when Group1_Print fires, I try to add records to summset but I get a "object not set" error. So I put in a few Msgbox's, and Report_Activate was not getting fired before Group1_Print, so the summset was not getting opened.
NOTE: I commonly have the report in design mode, then go to preview mode. This may have something to do with Report_Activate not getting fired. I need to find out events which get fired when I go from design mode to report preview mode.
I'm in a situation where I need to open a recordset named "summset" when a report opens, in a Group1_Print event I need to save records with summary totals to an existing table "CommSumm", then when the report closes I need to close my recordset. I need this opened recordset ("summset") available in all areas of the report. I did make my varitable a public variable at the report level:
public summset as dao.recordset
I was putting my recordset open in my Report_Activate event but it is not getting fired before the Group1_Print event. Then I put my recordset close in my Report_Deactivate event.
Code:
Private Sub Report_Activate()
Dim mo As String, yr As String
Dim crit As String
On Error GoTo MyError
Call InitGlobal ' Basically grabs network username. Does not touch recordsets.
Set MyDB = CurrentDb()
Set errset = MyDB.OpenRecordset("ErrTable", dbOpenDynaset) ' Used to save errors
Set summset = MyDB.OpenRecordset("CommSumm", dbOpenDynaset)
' First delete all records for this period from table CommSumm.
mo = Format(Forms("00Main")!txtBeginDate, "mm")
yr = Format(Forms("00main")!txtBeginDate, "yyyy")
crit = "DELETE FROM CommSumm WHERE period='" & yr & "-" & mo & "';"
DoCmd.SetWarnings False
DoCmd.RunSQL (crit)
DoCmd.SetWarnings True
You see, when Group1_Print fires, I try to add records to summset but I get a "object not set" error. So I put in a few Msgbox's, and Report_Activate was not getting fired before Group1_Print, so the summset was not getting opened.
NOTE: I commonly have the report in design mode, then go to preview mode. This may have something to do with Report_Activate not getting fired. I need to find out events which get fired when I go from design mode to report preview mode.