VB Code to Specify a Sub-Report

  • Thread starter Thread starter Jim Pockmire
  • Start date Start date
J

Jim Pockmire

Is it possible to use VB code to specify the source of a subreport in the
detail section of a main report, and linking fields as well. If so, what
code should I use and what event would this be set in?
 
Jim said:
Is it possible to use VB code to specify the source of a subreport in the
detail section of a main report, and linking fields as well. If so, what
code should I use and what event would this be set in?

A subreport's (or report's) RecordSource property can only
be set in the Open event of the subreport, and even then it
can only be done the first time the subreport is opened.
The code is pretty straight forward:

Me.RecordSource = queryname
or
strSQL = "SELECT . . . "
Me.RecordSource = strSQL

I'm pretty sure that setting the LinkMaster/Child properties
for the subreport control on the main report can only be
done in the main report's Open event.

Me.LinkMaster = "controlname"
Me.LinkChild = "fieldname"

If you were think of trying to do this for each main report
detail record, forget about doing it this way.
 
I would like to use code to specify one of five sub-reports. Does the
"SourceObject" property have any relavence to this?
 
Jim said:
I would like to use code to specify one of five sub-reports. Does the
"SourceObject" property have any relavence to this?

Yes, BUT, again, I believe you can only set it in the main
report's Open event:

Me.subreportcontrol.SourceObject = "nameofsubreport"[/QUOTE]
 
If you have data in the main Report on which to base the decision, you can
overlay five Sub-Report Controls, and use the Visible property of the
SubReport Controls to display only the pertinent one in each Detail Record.
I believe you can do this in the Format or Print event.

It will take a bit longer to run, because even though not visible, there's
overhead in populating the Forms embedded in the invisible Subreport
controls.

Larry Linson
Microsoft Access MVP
 
Larry said:
If you have data in the main Report on which to base the decision, you can
overlay five Sub-Report Controls, and use the Visible property of the
SubReport Controls to display only the pertinent one in each Detail Record.
I believe you can do this in the Format or Print event.

It will take a bit longer to run, because even though not visible, there's
overhead in populating the Forms embedded in the invisible Subreport
controls.

Good point Larry.

This way, the Link Master/Child properties for each
subreport control can be set at design time.
 
Back
Top