Sub-report problem

  • Thread starter Thread starter Bill Stanton
  • Start date Start date
B

Bill Stanton

I'm unable to get a sub-report to function properly
when running as a sub-report. I.e., it will preview
correctly when executed as a stand-alone report,
but as soon as I try to run the sub-report inserted
into the main report, I get a run-time error when
the OnOpen code attempts to set the filter for the
RecordSource, which is a Union Select query.

I've attempted to get the sub-report to inherit the
RecordSource of the main report by setting the
RecordSource of the sub-report to blanks, but
that doesn't work either.

The reason for the sub-report is that it needs to
group differently than does the main. E.g., the
main report groups by "title" and the "title" footer
has a control that displays SUM(Amount) for
each "title". The sub-report groups by "type"
and the "type" footer has a control that displays
SUM(Amount) for each "type".

The OnOpen code for the main report determines
what the RecordSource filter needs to be from
the user when the report is initiated and both the
main and sub-reports need to use the same
filtered RecordSource.

So, the question is: How do I get the sub-report
to use the same RecordSource as the main?

Thanks,
Bill
 
Bill said:
I'm unable to get a sub-report to function properly
when running as a sub-report. I.e., it will preview
correctly when executed as a stand-alone report,
but as soon as I try to run the sub-report inserted
into the main report, I get a run-time error when
the OnOpen code attempts to set the filter for the
RecordSource, which is a Union Select query.

I've attempted to get the sub-report to inherit the
RecordSource of the main report by setting the
RecordSource of the sub-report to blanks, but
that doesn't work either.

The reason for the sub-report is that it needs to
group differently than does the main. E.g., the
main report groups by "title" and the "title" footer
has a control that displays SUM(Amount) for
each "title". The sub-report groups by "type"
and the "type" footer has a control that displays
SUM(Amount) for each "type".

The OnOpen code for the main report determines
what the RecordSource filter needs to be from
the user when the report is initiated and both the
main and sub-reports need to use the same
filtered RecordSource.

So, the question is: How do I get the sub-report
to use the same RecordSource as the main?


You can only set the subreport's RecordSource property the
first time the subreport is processed, not for each
occurance in the main report.

This is easily done using a little code in the subreport's
Open event procedure:

Sub Report_Open( . . .
Static Initialized As Boolean

If Not Initialized Then
Me.RecordSource = whatever
Initialized = True
End If
. . .
 
Okay, thanks Marsh.

Rather than mess with creating global variables in a
general module, is there a syntax that will allow me
to access the main reports RecordSource and its
properties from the sub-report? Like:
Me.RecordSource = report!mainreportname.RecordSource
or something like that?

Bill
 
Bill said:
Rather than mess with creating global variables in a
general module, is there a syntax that will allow me
to access the main reports RecordSource and its
properties from the sub-report? Like:
Me.RecordSource = report!mainreportname.RecordSource
or something like that?

Sure, try this:

Me.RecordSource = Me.Parent.RecordSource
--
Marsh
MVP [MS Access]

 
Marsh,
Attempting to avoid convoluted threads, I posted the aftermath
of this thread as: Run-Time error 2101
Thanks,
Bill
 
Back
Top