Solved

substitute variable name in SET statement

Posted on 2015-01-08
2
122 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 119

Accepted Solution

by:
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now