Switching Printers using form

T

Tony_VBACoder

A much easier approach would be to have one list box with
all your Report, another list box with all your Printers,
and finally one button that would run the report the user
selected with the printer that the user selected.

If you are using Access 2002 and greater, you could loop
through the new Printers collection and fill your ListBox
with the names of the Printer. Then you could set the
Printer of the report to the Printer that the user
selected or you could set the Default Printer to the one
the user selected. The Default Printer method I have used
is outlined below:

To Loop through the Printer Collection and fill the list
box with the names of the Printer:
Dim prt As Printer, iCtr As Integer
For Each prt In Application.Printers
With prt
Me.ListBoxPrinters.AddItem .DeviceName, iCtr
End With
iCtr = iCtr + 1
Next

Then you can set the user's Default Printer to the one
they chose. You would first want to read their current
Default Printer into a variable, change it to the one they
chose, then set it back to their original printer by
reading your variable. The code could be something like
this:

Dim sMyDefPrinter As String
' Read the current default printer and save the value - we
will need this later when we reset the Default Printer
sMyDefPrinter = Application.Printer.DeviceName
' Change the default printer to the one they chose in the
list box
Set Application.Printer = Application.Printers(<< Put Your
Printer Here that the user chose >>)
' Open the Report
DoCmd.OpenReport "MySampleReport"
' Change the Printer back to the default printer
Set Application.Printer = Application.Printers
(sMyDefPrinter)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top