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 Reports in VBA

Status
Not open for further replies.

JohnnyProd

Technical User
Sep 25, 2001
12
0
0
US
How can I reference a label in a report without hardcoding the name?
ex: 'Reports![myReport]!lblDate.Caption = strHeader'

I've tried creating a <b>Report</b> object named myReportObject and then referencing it like 'myReportObject!lblDate.Caption = strHeader'. Unfortuantely, I am having probelms creating the <b>Report</b> object. Any tips? Here's an example of the code I am trying to implement.



reportName=&quot;myReport&quot;
DoCmd.OpenReport reportName, acDesign
Report myReport = Reports![Open Cursors]

Reports![myReport]!lblDate.Caption = strHeader
Reports![myReport]!lblDate.FontSize = fntSize
Reports![myReport]!Graph2.RowSource = sqlString

DoCmd.Close acReport, reportName, acSaveYes
DoCmd.OpenReport reportName, acPreview
 
My mistake. The line :

Report myReport = Reports![Open Cursors]

Should read

Report myReport = Reports![myReport]

to keep consistant.

 
Nevermind. It figures that after working on this for such a long time it wan't until minutes after making the post till I realized that I needed to Set myReport = Reports![myReport] in order to reference it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top