Order of Events

  • Thread starter Thread starter DK
  • Start date Start date
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
 
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
. . .
 
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
. . .
 
Back
Top