Solved

substitute variable name in SET statement

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

744 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

12 Experts available now in Live!

Get 1:1 Help Now