Reports and Sub Report

R

rberry

I have a dialogue form which generates a search variable called strWhere.
The on click event associated with a command button on the form then opens a
main report call it Report A with an embedded sub-report call it Report B.

I use the varable strWhere in the open event of Report A to set the filter
property associated with main report.

Problem is when I try to repeat the exercise in the sub report (Report B) it
comes up with 'invalid reference' or Application Defined or Object Defined
Error 2101'

I think it is in the explict referencing I am using to define the sub report
in the open event of Report B i.e.

Reports!ReportA!ReportB.Filter = StrWhere
 
S

strive4peace

ReportB would be a reference to the subreport control -- not the report
IN the control -- you need to add .Report

Reports!ReportA!ReportB.Report.Filter = StrWhere

then, you would need to set FilterOn = True

you should be able to use a relative reference, like this:

Me.ReportB.Report.Filter = StrWhere
Me.ReportB.Report.FilterOn = True

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
R

rberry

Crystal
Moving from the generic to the specific:
Report A - rptTest (Main Report)
Report B - rptSubPathwayActivity (Sub Report)
Pathway - Control referencing referencing rptSubPathwayActivity within main
report rptTest.

Using the logic in you first paragraph of your response, have set the line
of code WITHIN the open event of the sub report rptSubPathwayActiivty:

"Reports!rptTest!Pathway.Report.Filter=strWhere"

Sorry, no joy with your suggestion error message "Run Time Error 2465 -
Application Defined or Object Defined Error"

PS I noticed that there are no events associated with the Pathway Control
only the sub report itself. Clearly my reference to the sub report leaves
something to be worked on.

The Rocket
 
S

strive4peace

if you are in code behind the main report, use a relative reference to
the subreport

Me.ReportB.Report.Filter = StrWhere
Me.ReportB.Report.FilterOn = True

make sure StrWhere is defined and is valid. If you are constructing it
in code, do this:

debug.print StrWhere

after you run the code, press CTRL-G (Goto debuG (Immediate) Window)

then you can examine what the value is and make sure it is right


'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code, references, or switch versions, you should
always compile before executing.

from the menu in a VBE (module) window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

~~
if you run code without compiling it, you risk corrupting your database


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
R

rberry

crystal
Have:
* changed the code to "Me.Pathway.Report.Filter = StrWhere"
"Me.Pathway.Report.FilterOn = True"
* Checked that StrWhere is defined and valid - it is!
* Compiled VBA code - it does!

Now getting the error message "2455 - Invalid Ref to Property for Form/Report"

Question a) the control (pathway) on the main report that contains the
sub-report does not have any events associated with it so how can I set its
filter property?

and

b) if I am in the open event of the main report does that mean the the
sub-report is also open. If not is that why I can't properly reference the
sub report and why the erro messages keep on coming up.

Regards
The Rocket
 
S

strive4peace

I do not actually use this method. If I want to set a filter on a
subreport, I open it in design view and change it before the main report
is rendered. If the subreport depends on data that is in the main
report, it would work best to use the LinkMasterFields and
LinkChildFields properties of the subreport control

read this and pay close attention to the section on mainform/subforms --
reports work the same way

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace


Warm Regards,
Crystal

*
:) have an awesome day :)
*
 
R

rberry

This worked fine. Many thanks.

strive4peace said:
I do not actually use this method. If I want to set a filter on a
subreport, I open it in design view and change it before the main report
is rendered. If the subreport depends on data that is in the main
report, it would work best to use the LinkMasterFields and
LinkChildFields properties of the subreport control

read this and pay close attention to the section on mainform/subforms --
reports work the same way

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace


Warm Regards,
Crystal

*
:) have an awesome day :)
*
 

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