Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

substitute variable name in SET statement

Posted on 2015-01-08
2
Medium Priority
?
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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