Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a subreport in VBA 2

Status
Not open for further replies.

RDS2

Technical User
Jun 6, 2003
44
US
I want to change the RecordSource property of a sub-report when the main report opens.

In my case the sub-report name is "Rpt_r&a_tdoc".

The code in the main report event "On Open" is:

"Me.Rpt_r&a_tdoc.RecordSource = Qry_docrev_tdoc"

This bombs the report out - but - I'm not sure where the error is occuring.

Any ideas?
 
Most of us veterans (old-timers) would never use symbols like "&" in an object name. If you feel you need to use these (and/or spaces) you have to wrap the names in []s.

Try code like:
Code:
  Me.[Rpt_r&a_tdoc].Report.RecordSource = "Qry_docrev_tdoc"

I'm not sure if this will work but it should get you closer. I generally change the SQL property of a saved query prior to opening the main report.


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
dhookum, RDS2 mentions the open event of the main report. I find that changing the record source of a subform in that event will cause an error. I find that the open event of the subform itself is more suited to changing the recordsource, unless, of course, RDS2 takes your approach and changes the query.

In addition, my version of Access replace the ampersand with an underscore in the name of the control when using intellisense.
 
Thanks posters - dhookom; your code attached to the command button that loads the report gets the job done. I understand the ampersand issue - many times my fingers are a "ketstroke" ahead of my brain!

Merci.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top