How to refer to form using a variable? (1 Viewer)

cricketbird

Registered User.
Local time
Today, 11:34
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Feb 19, 2002
Messages
43,275
rpt.Printer.paperSize = pSize

"AllReports" might be only open reports so you may have to use a different collection.
 

cricketbird

Registered User.
Local time
Today, 11:34
Joined
Jun 17, 2013
Messages
108
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Feb 19, 2002
Messages
43,275
If you want us to test your code, you need to upload a database.
 

cricketbird

Registered User.
Local time
Today, 11:34
Joined
Jun 17, 2013
Messages
108
Here's an example
 

Attachments

  • PaperSizes.accdb
    512 KB · Views: 42

Josef P.

Well-known member
Local time
Today, 17:34
Joined
Feb 2, 2023
Messages
826
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

Top Bottom