May 5, 2010 #1 coolscan3 Programmer Oct 23, 2001 40 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
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
May 5, 2010 #2 Remou Technical User Sep 30, 2002 13,030 BE 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 http://lessthandot.com Upvote 0 Downvote
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 http://lessthandot.com
May 5, 2010 Thread starter #3 coolscan3 Programmer Oct 23, 2001 40 GB Thanks, the reports() was what I was missing Upvote 0 Downvote
May 5, 2010 #4 dhookom Programmer Jun 24, 2003 22,497 US 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 Upvote 0 Downvote
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