Order of Events

D

DK

I have a report/subreport where the recordsource of the subreport is set at
runtime via code entered in the subreport's open event. This works fine
except when I enter code in the ReportHeader_Format event on the main
report. This event causes the subreport to reopen and I get an error.
Once in print mode the data source of the subreport cannot be set via the
open event. Any suggestions as to how this can be handled? Thanks.

DK
 
M

Marshall Barton

DK said:
I have a report/subreport where the recordsource of the subreport is set at
runtime via code entered in the subreport's open event. This works fine
except when I enter code in the ReportHeader_Format event on the main
report. This event causes the subreport to reopen and I get an error.
Once in print mode the data source of the subreport cannot be set via the
open event.

The problem is that the subreport's Open event fires for
each instance of the subreport, but several properties such
as RecordSource can not be set after the report starts
printing (i.e. it can only be set the first time). To deal
with this, use code in the subreport Open event to prevent
the code from running more than once.

Sub Report_Open( . . .
Static Initialized As Boolean

If Not Initialized Then
Me.RecordSource = . . .
Initialized = True
End If
. . .
 
D

DK

Thanks Marshall, that solved it.

Marshall Barton said:
The problem is that the subreport's Open event fires for
each instance of the subreport, but several properties such
as RecordSource can not be set after the report starts
printing (i.e. it can only be set the first time). To deal
with this, use code in the subreport Open event to prevent
the code from running more than once.

Sub Report_Open( . . .
Static Initialized As Boolean

If Not Initialized Then
Me.RecordSource = . . .
Initialized = True
End If
. . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top