G
Guest
HI
I need to set the record source in a report. It appears that this can only be done in the OnOpen event. I need to use the report with several different queries. I can set the record source in the OnOpen event but it seems to only be called once for a given report per session in Access. So doing this with DoCmd.OpenReport does not work as the OnOpen event is not called on the 2nd to nth call, only the first. The idea of opening the form in acViewDesign mode setting the record source then opening in acViewNormal works sometimes but causes Access to crash on others. This is not very satisfactory as it will not work anyway in a .mde. The best I have so far is as follows
Dim Rpt As Repor
gReportDataSource = "qry_NonSPS
gReportFilter = "[ShipDate]>#01/1/2004# AND [ShipDate]<#1/1/2005#
gReportTitle = "Independent Customer Sales 2004 year to date
Set Rpt = New Report_rpt_MyRepor
Rpt.Visible = Tru
The OnOpen event for the new instance of the report is fired and can set the appropriate data from the global variables (hack hack) but it does the job. The problem at this point is that the report displays in a window and I need it to print. DoCmd.Print does not work because the window does not have the focus. DoCmd.SelectObject does not work because the new instance is not in the Forms collection. (Who designed this mess anyway?) I should be able to create a new instance of a class (report) manupulate its properties then run it. Instead it runs in the Set Rpt= statement and after that its too late
Charlie
The handling of reports is strange. The OnOpen Event does not fire each time DoCmd.OpenForm is called even with DoCmd.Close is called for the form before the OpenForm Call.
I need to set the record source in a report. It appears that this can only be done in the OnOpen event. I need to use the report with several different queries. I can set the record source in the OnOpen event but it seems to only be called once for a given report per session in Access. So doing this with DoCmd.OpenReport does not work as the OnOpen event is not called on the 2nd to nth call, only the first. The idea of opening the form in acViewDesign mode setting the record source then opening in acViewNormal works sometimes but causes Access to crash on others. This is not very satisfactory as it will not work anyway in a .mde. The best I have so far is as follows
Dim Rpt As Repor
gReportDataSource = "qry_NonSPS
gReportFilter = "[ShipDate]>#01/1/2004# AND [ShipDate]<#1/1/2005#
gReportTitle = "Independent Customer Sales 2004 year to date
Set Rpt = New Report_rpt_MyRepor
Rpt.Visible = Tru
The OnOpen event for the new instance of the report is fired and can set the appropriate data from the global variables (hack hack) but it does the job. The problem at this point is that the report displays in a window and I need it to print. DoCmd.Print does not work because the window does not have the focus. DoCmd.SelectObject does not work because the new instance is not in the Forms collection. (Who designed this mess anyway?) I should be able to create a new instance of a class (report) manupulate its properties then run it. Instead it runs in the Set Rpt= statement and after that its too late
Charlie
The handling of reports is strange. The OnOpen Event does not fire each time DoCmd.OpenForm is called even with DoCmd.Close is called for the form before the OpenForm Call.