Link to home
Start Free TrialLog in
Avatar of rodneygray
rodneygrayFlag for United States of America

asked on

Select Default Printers for Specific Reports

I am completing a project and I cannot figure out how to assign specific printers to reports. I will be printing two types of reports . One will be a regular report and will be directed to a laserjet printer. The other report will be directed to a Zebra label printer. This project will be distrubuted with run-time so the full version of Access will not be available.
I have a company master table that has two fields labeled ReportsPrinter and LabelPrinter. I want to create a combobox that will populate with the printers available on the user's workstation. Then the user will be able to select the printer they wish to use for reports and labels. When I call the report I want to pull the printer name from the Company Master fields and send the report / labels to the correct printer.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image


  You can use this more or less
    Dim prt As Printer
   
    With Application
        Set prt = .Printer  'Save current Default Printer
        .Printer = Application.Printers("YourSpecialPrinterNameHere")
         DoCmd.OpenReport "SomeReportName", acViewNormal      
        .Printer = prt      'Put back Default Printer        
    End With

mx

You can do this to list printers:


    Dim x
    For x = 0 To Application.Printers.Count - 1
        Debug.Print Application.Printers.Item(x).DeviceName & "  " & x
    Next x

You could fill a combo box RowSource with this, and RowSource Type would be Value List.
Unless I am misunderstanding something you can set the report to always print to a specific printer.

Open the report in design view
In Page setup, click the "Page" tab
Under: "Printer for rtpXXXX", select:  "Use Specific Printer"
Then click the printer button and select the printer you need.
Click OK, save the report.
Compact/repair the DB for good measure, then test.

JeffCoachman
I suspect the OP means in code ...

mx
Avatar of rodneygray

ASKER

Boag2000: DB will be distributed as runtime. I need a method to allow users to select printer to use for reports and labels. I will store that value in the company table. On the company form, I will have two fields, ReportPrinter and LabelPrinter. Program will then be able to lookup printer value from Company table and print correct report/label to specified printer.
DatabaseMX: I am trying to implement your code now.
DatabaseMX: How do I populate a comboBox with the printer values?
DatabaseMX: Should I make the "filling a comboBox" via VBA another question? The only method that occurs to me is to create a table, populate the table with printer values and then set source of comboBox to the table. I would have to repopulate the table each time the Company form was opened.
DatabaseMX: Used the following code to populate with available printers.
    Me.cmboReportPrinter.RowSource = ""
    For Each prt In Application.Printers
        Me.cmboReportPrinter.AddItem prt.DeviceName
    Next
Hope this articles will work for you:
http://support.microsoft.com/kb/319317

Or this solution provided by Allen Browne:
http://allenbrowne.com/AppPrintMgt.html

Hope this helps,
Daniel
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
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