Solved

substitute variable name in SET statement

Posted on 2015-01-08
2
123 Views
Last Modified: 2015-01-08
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
0
Comment
Question by:Rob4077
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40539142
try
Set rpt = Reports(ReportName)


what happen if you just use

 With Reports(ReportName).Printer
0
 

Author Comment

by:Rob4077
ID: 40539214
Thanks Rey. The "With Reports(ReportName).Printer" option worked fine. Appreciate your help
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question