How to refer to form using a variable?

cricketbird

Registered User.
Local time
Today, 09:20
Joined
Jun 17, 2013
Messages
108
I'm trying to create a setting that cycles through all my reports and changes them all to A4 (or vice versa to Letter).

The following code almost works, but I can't seem to refer to the reports correctly. What am I missing?

Code:
Public Sub UpdateReportPageSize(pSize As Integer)
' 1 = Letter;  9 = A4

Dim rpt As Object
For Each rpt In Application.CurrentProject.AllReports
    Debug.Print rpt.Name
    DoCmd.OpenReport rpt.Name, acViewDesign
    Reports(rpt.Printer.paperSize) = pSize
    DoCmd.Close acReport, rpt.Name
Next
End Sub

I've also tried Reports!rpt.Printer.paperSize and saving the whole thing as a string, but no luck.
 
rpt.Printer.paperSize = pSize

"AllReports" might be only open reports so you may have to use a different collection.
 
rpt.Printer.paperSize = pSize

"AllReports" might be only open reports so you may have to use a different collection.
Thanks! I tried that and got a new error:
Runtime error 438 Object doesn't support this property or method.
 
If you want us to test your code, you need to upload a database.
 
Code:
Dim rpt As AccessObject
For Each rpt In Application.CurrentProject.AllReports
    Debug.Print rpt.Name
    DoCmd.OpenReport rpt.Name, acViewDesign
    Reports(rpt.Name).Printer.PaperSize = pSize
    Application.RunCommand acCmdSave  '<-- I had to add this, otherwise the setting was not saved
    DoCmd.Close acReport, rpt.Name, acSaveYes
Next
 

Users who are viewing this thread

Back
Top Bottom