Set Recordsource for a subreport

G

Guest

Does anyone know how to set the recordsource for a subreport within a report?

So let's say I have Report1 as my report and subrpt1 as my subreport. Where
would I set the recordsource for subrpt1?

Thanks for any help.

Sarah
 
M

Marshall Barton

Sarah said:
Does anyone know how to set the recordsource for a subreport within a report?

So let's say I have Report1 as my report and subrpt1 as my subreport. Where
would I set the recordsource for subrpt1?


The **only** place that you can set a report's record source
is in its own Open event procedure. Not only that, but you
can not run the code more than once if the subreport might
appear multiple times in the print out.
 
G

Guest

I tried doing that, but I get an error that says cannot set property after
printing has started. So it sounds like this can't be done.

Thank you.

Sarah
 
M

Marshall Barton

Well, you have not explained what "this" is, but as I said
before, you can only execute the code in the subreport's
Open event once. So, if you want different instances of a
subreport to use different record source tables/queries,
then it can not be done.

However, if you want all instances of the subreport to use
the same record source, then you can use code like this in
the subreport's Open event:

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