Setting subreport recordsource dynamically

  • Thread starter Thread starter Dene
  • Start date Start date
D

Dene

I'm looking for some help with a report which contains a
subreport. I want to change the recordsource of both the
report and subreport dynamically depending upon options
chosen by a user on a form. I can get this to work for
the main report using VBA on open but I can't get the same
thing to happen to the sub report.

Any help in getting the recorsdsource for the sub report
to change dynamically would be greatly appreciated.

Regards


Dene
 
-----Original Message-----
I'm looking for some help with a report which contains a
subreport. I want to change the recordsource of both the
report and subreport dynamically depending upon options
chosen by a user on a form. I can get this to work for
the main report using VBA on open but I can't get the same
thing to happen to the sub report.

Any help in getting the recorsdsource for the sub report
to change dynamically would be greatly appreciated.

Regards
I would recomend to use following scenario:
from the point where you start the report you can set data
source for your reports or subreports if you do few steps:
DoCmd.Echo False 'to shut down visual staff
DoCmd.Echo False
DoCmd.OpenReport stDocName, acViewDesign
Reports(stDocName).RecordSource = strQuery
DoCmd.Close acReport, stDocName, acSaveYes
DoCmd.Echo True
 
Dene said:
I'm looking for some help with a report which contains a
subreport. I want to change the recordsource of both the
report and subreport dynamically depending upon options
chosen by a user on a form. I can get this to work for
the main report using VBA on open but I can't get the same
thing to happen to the sub report.

You can change the subreport's record source on the fly, BUT
only the first time the subreport's Open event fires. Add a
little code to check if the subreport has already been
opened and skip the record source code after the first time:

Sub Report_Open( . . .
Static Initialized As Boolean

If Not Initialized Then
Me.RecordSource = "whatever"
Initialized = True
End If
 
Back
Top