C
Carl Colijn
Hi all,
I am generating instances of my reports on the fly via Set = New
Report_MyReportName. This I do to be able to open the same report twice in
preview mode with different sets of data.
However, I have read somewhere that when the variable that holds the newly
created report instance goes out of scope, the report will be closed as
well. The solution would be to hold on to the report in a wider scope, and
release it when not needed anymore. The latter also included removing it
from the report's Close event. Quite do-able, but a lot of administration
to get it to work.
However: I'm using Access 2003, generating reports on the fly in VBA, and I
do let the variables go out of scope. But the reports do not close! The
thing that did the trick was to use a DoCmd.Maximize in the report's Open
event; if I remove that statement, the report closes automatically again.
Now I do want my reports maximized on open, but I also need this code to
work reliably in Access 2002, a version which I do not have around to test
on. The exact steps I take are listed below. The report is configured as
modal=no, popup=no and border=sizeable.
Can someone tell me if I can rely on the Maximize to keep the report open
even if it's instance variable goes out of scope?
Thanks in advance,
Carl
===========================
Global module
===========================
Function MakeReport()
Dim oNewReport As Report
Set oNewReport = New Report_ReportName
Call oNewReport.Setup(nParam1, sParam2, etc.)
End Function
===========================
Report_ReportName's module
This is all the code that's in the module;
no other events are coded.
===========================
Private Sub Report_Open(bCancel As Integer)
Call DoCmd.Maximize
oMyControl.Format = g_csDateTimeFormat
End Sub
Public Sub Setup(nParam1 As Long, sParam2 As String)
Filter = "Criteria=" & nParam1 & " And OtherCriteria='" & sParam2 & "'"
FilterOn = True
End Sub
I am generating instances of my reports on the fly via Set = New
Report_MyReportName. This I do to be able to open the same report twice in
preview mode with different sets of data.
However, I have read somewhere that when the variable that holds the newly
created report instance goes out of scope, the report will be closed as
well. The solution would be to hold on to the report in a wider scope, and
release it when not needed anymore. The latter also included removing it
from the report's Close event. Quite do-able, but a lot of administration
to get it to work.
However: I'm using Access 2003, generating reports on the fly in VBA, and I
do let the variables go out of scope. But the reports do not close! The
thing that did the trick was to use a DoCmd.Maximize in the report's Open
event; if I remove that statement, the report closes automatically again.
Now I do want my reports maximized on open, but I also need this code to
work reliably in Access 2002, a version which I do not have around to test
on. The exact steps I take are listed below. The report is configured as
modal=no, popup=no and border=sizeable.
Can someone tell me if I can rely on the Maximize to keep the report open
even if it's instance variable goes out of scope?
Thanks in advance,
Carl
===========================
Global module
===========================
Function MakeReport()
Dim oNewReport As Report
Set oNewReport = New Report_ReportName
Call oNewReport.Setup(nParam1, sParam2, etc.)
End Function
===========================
Report_ReportName's module
This is all the code that's in the module;
no other events are coded.
===========================
Private Sub Report_Open(bCancel As Integer)
Call DoCmd.Maximize
oMyControl.Format = g_csDateTimeFormat
End Sub
Public Sub Setup(nParam1 As Long, sParam2 As String)
Filter = "Criteria=" & nParam1 & " And OtherCriteria='" & sParam2 & "'"
FilterOn = True
End Sub