Switching Printers using form

  • Thread starter Thread starter ChrisBat
  • Start date Start date
C

ChrisBat

Hi,

I would like to build a form that will have three or four
different buttons (one for every report that I need to
run) and then two Option Buttons that will enable me to
send the reports to one of two different printers (I'll
select the printer, select the report, and then go from
there).
The problem is that I can't seem to figure out how to send
something to a printer other than my default, and I can't
figure out how to do it via VBA. Any suggestions?
Thanks in advance,
Chris
 
I have a sample application on how to do this.

Note that access XP does have built in the ability to switch printers. So,
while my code *should* work, you do NOT need it in a2002.

You can use:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

So, to save/switch, you can use:

dim strDefaultPrinter as string

' get current defualt printer.
strDefaultPrinter = Application.Printer.DeviceName

' swtich to printer of your choice:

Set Application.Printer = Application.Printers("HP LaserJet Series II")

do whatever.

Swtich back.

Set Application.Printer = Application.Printers(strDefaultPrinter)


If you are using a earlier version then access 2002, then the above will not
work...

you can grab my sample change code at:

http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html
 
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)
 
Back
Top