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!

Report Recordsource Reference

Status
Not open for further replies.

coolscan3

Programmer
Oct 23, 2001
40
0
0
GB
Is it possible to refer to a reports recordsource using a variable eg.

DoCmd.OpenReport Variable1 & "Report2", acViewDesign, , , acHidden

Reports!Variable1.RecordSource = sqlstr

DoCmd.Close acReport, Variable1 & "Report2", acSaveYes
 
Yes. Report name is a string, so to simplify:

sReportName= Variable1 & "Report2"

You can then use the string where you want:

DoCmd.OpenReport sReportName, acViewDesign, , , acHidden

Note that you can use parentheses to refer to forms, controls, etc, etc.

Reports(sReportName).RecordSource = sqlstr

DoCmd.Close acReport, sReportName, acSaveYes


 
Thanks, the reports() was what I was missing
 
I would rather base the report on a saved query and then use a little DAO to change the SQL property of the query prior to opening the report.

I prefer not run code from outside the report that changes the report as it opens or when in design view.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top