Setting subreport recordsource dynamically

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
 
M

MikeTorn

-----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
 
M

Marshall Barton

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
 

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