After the default printer has been changed by code in Access 2003, the application still directs a r

P

Peanuts

Could someone please help? I am using the 'defaultprt.zip' tool
provided by Ken Getz to change the default printer via VBA code (code
below). My problem is that once the default printer has been changed,
Access 2003 still directs the report to the former default printer.
Access 2003 picks up the new default printer setting only after I have
reopened the application. I have checked the default printer setting in

the OS control panel and the code works well. This problem also occurs
when an Access 2003 application is open and one changes the default
printer manually in the control panel (Windows 2000).

To me it seems that Access 2003 picks up the default printer setting
once at Application Start-up only. Is there a way that I can force
Access to "refresh" the default printer after I have changed it by
code without closing/reopening the application?


THANKS


Code to SET DEFAULT PRINTER by Ken Getz:
Option Compare Database 'Use database order for string comparisons
Option Explicit


' Code from:
' Microsoft Access 95 How-To
' (c) 1998 Ken Getz and Paul Litwin
' All rights reserved.


' You may only use this code as part of an application
' that requires its use. You must including this
' notice intact. You may not distribute the code
' as your own work, nor can you distribute the
' code on its own.


Private Function BuildName(dr As aht_tagDeviceRec) As Variant


' Build up the string in the format:
' HP LaserJet 4 on LPT1:
' for display in the combo box.


BuildName = dr.drDeviceName & " on " & dr.drPort


End Function


Private Sub Button0_Click()


DoCmd.Close


End Sub
 
D

Douglas J Steele

Access 2003 actually has a Printers collection that you can manipulate
directly, rather than needing Ken's code.

Unfortunately, I don't have Access 2003 loaded on this machine, so I can't
give you specific instructions in how to work with the collection.
 
A

Albert D.Kallal

In access 2002 and later, there is a built in printer object, and it lets
you switch the printer with ease.

You can use:

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

The above means you don't need that complex and difficult to use printer
swithc code (which by the way is very old...for windows 95...).

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)
 

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