• Change report’s PaperSize with VBA

    Author
    Topic
    #2554219

    The following code snippet appears to change the papersize, but it does not “stick” with the report. The debug line with “save” seems to indicate that the report has the correct papersize, but immediately reopening the report shows that the papersize has reverted to its original setting. Occasionally it works when single-stepping through the code, but I haven’t found any bulletproof way for it to always work. What am I missing?

    If vbYes = MsgBox(“Confirm you want to ” & vbCrLf & _
    “change the report’s FormID to: ” & iPapersize, vbYesNo, “About to modify: ” & sReportName) Then

    DoCmd.OpenReport sReportName, View:=acViewDesign
    Debug.Print “Device: ” & Reports(sReportName).Printer.DeviceName

    Debug.Print “open: ” & Reports(sReportName).Printer.PaperSize
    Reports(sReportName).Printer.PaperSize = iPapersize
    Debug.Print “assign: ” & Reports(sReportName).Printer.PaperSize
    DoEvents

    DoCmd.Save acReport, sReportName
    Debug.Print “saved: ” & Reports(sReportName).Printer.PaperSize
    DoCmd.Close acReport, sReportName, acSaveYes

    DoCmd.OpenReport sReportName, View:=acViewDesign
    Debug.Print “reopen: ” & Reports(sReportName).Printer.PaperSize
    DoCmd.Close acReport, sReportName, acSaveYes

    MsgBox “Done”

    End If

    Viewing 0 reply threads
    Author
    Replies
    • #2554463

      Finally figured it out. DoCmd.Save does not work. The only way to persist the report settings is to leave the report open in Design View, manually Save it from the Access menu, and then close it. SendKeys does not even work – it must be done manually.

    Viewing 0 reply threads
    Reply To: Change report’s PaperSize with VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: