Link to home
Start Free TrialLog in
Avatar of Rob4077
Rob4077Flag for Australia

asked on

substitute variable name in SET statement

I have a need to print selected reports double sided and found the following function on a MS support web site that should do what I want. To make it more functional I want to turn it into a function that accepts the report name as parameter. However I am not sure how to use that name in the Set statement (see below). Can anyone help?
 
Private Sub PrintCatalogReport()
    Dim rpt As Report
    Application.Printer = Application.Printers(0)
    DoCmd.OpenReport "Catalog", acViewPreview, , , acHidden
    Set rpt = Reports!Catalog
    With rpt.Printer
        .BottomMargin = 720
        .Copies = 2
        .Duplex = acPRDPVertical 'Double sided
        .PaperBin = acPRBNLargeCapacity
    End With
    DoCmd.OpenReport "Catalog", acViewNormal
    DoCmd.Close acReport, "Catalog", acSaveNo
    Set Application.Printer = Nothing
End Sub

Private Sub PrintDoubleSidedReport(ReportName As String)
    Dim rpt As Report
    Application.Printer = Application.Printers(0)
    DoCmd.OpenReport ReportName, acViewPreview, , , acHidden
    Set rpt = Reports!ReportName                              'THIS IS WHERE I NEED HELP
   
    With rpt.Printer
'        .BottomMargin = 720
        .Copies = 1
        .Duplex = acPRDPVertical    'Double sided
'        .PaperBin = acPRBNLargeCapacity
    End With
    DoCmd.OpenReport ReportName, acViewNormal
    DoCmd.Close acReport, ReportName, acSaveNo
    Set Application.Printer = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rob4077

ASKER

Thanks Rey. The "With Reports(ReportName).Printer" option worked fine. Appreciate your help