Change the RecordSource for a subreport

C

Carl Rapson

Is it possible to change the RecordSource property of a subreport? I have a
report that contains several subreports, and I need to change the
RecordSource of several at runtime. In the Open event, I have lines like

<subreport name>.Report.RecordSource = "..."

but I get the following runtime message:

Run-time error '2455':
You entered an expression that has as invalid reference to the property
Form/Report.

I don't know if it makes any difference, but the subreports are not linked
to the main report -- I'm using the main report simply as a "vessel" to
produce the subreports.

Is it possible to change the subreport's RecordSource? If so, where or how
do I need to do it?

Thanks for any information,

Carl Rapson
 
M

Marshall Barton

Carl said:
Is it possible to change the RecordSource property of a subreport? I have a
report that contains several subreports, and I need to change the
RecordSource of several at runtime. In the Open event, I have lines like

<subreport name>.Report.RecordSource = "..."

but I get the following runtime message:

Run-time error '2455':
You entered an expression that has as invalid reference to the property
Form/Report.

I don't know if it makes any difference, but the subreports are not linked
to the main report -- I'm using the main report simply as a "vessel" to
produce the subreports.

Is it possible to change the subreport's RecordSource? If so, where or how
do I need to do it?


You can only do that in each subreport's Open event.

There's an added twist though, if a subreport has multiple
instances (as in a repeating section (e.g. detail) of the
main report), you can only set its record source the first
time. It doesn't sound like you have this situation so I
won't go into details.
 
C

Carl Rapson

How embarrassing. I forgot about changing the RecordSource in the
subreport's Open event (which is strange since I was trying to do it in the
main report's Open event, because I knew that's the only place the
RecordSource can be changed). I can simply pass the new string to the
subreport through OpenArgs.

And, you are right about only having a single instance of each subreport.

Thanks for not rubbing it in,

Carl
 
D

Dennis Snelgrove

I've been looking at the Events for the report, and I can't find any for the
subreport object. If my subreport container is called "srptDetail", how
would I insert an appropriate Event to set the Recordsource for the
subreport? Or should I be using the main report's Open Event?
 
I

IndianaJonesWB

I figured it out (I think, it works for me at least).

in the subforms open event reference the arguements in the parent form
using .parent

For example, I have a main report that I may open with
DoCmd.OpenReport "rptName", acViewPreview, , , , "@stopstatus=300"

in the Main reports open event I do
me.recordsorce = "exec dbo.spWhatever " & me.openargs

in the Sub Reports open event I do
me.recordsorce = "exec dbo.spWhatever2 " & me.parent.openargs

So Far it's working fine.
Just tested it once though.

Does this help?
 
I

IndianaJonesWB

BTW I think I screwed up.

instead of
me.parent.openargs

I meant to type

me.parent.report.openargs
 

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