Setting default printer programmatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created an application that allows users print quotes but i only want
them to print to their designated network printer. i had some code that
would change the default printer if it wasnt their network printer(see
below). it worked fine in access 2002 but when i upgraded to 2003 it stopped
working. when i run it it give a run-time error '5': Invalid prodecure call
or argument. does code not work in 2003 or is different now?

:: old code ::
Dim tempPrinter As Printer
Set tempPrinter = Application.Printers(Me.txtSetPrinter.Value)
Set Application.Printer = tempPrinter



thanks.
 
Hum, I used the follwing:


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 default printer.
strDefaultPrinter = Application.Printer.DeviceName

' switch to printer of your choice:

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

do whatever.

Swtich back.

Set Application.Printer = Application.Printers(strDefaultPrinter)

Note how I just used string to capture the current printer name...and you
dimed it as "printer"

Try the above....
 
Back
Top