Get default printer name

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Access 2003.

Using VBA how do I get the default printer (or current printer) name, switch
to a different printer to print a report, then revert back to my default
printer?

Thanks for any help.

Adrian
 
If you always want to use the same printer for a report, open the report in
design view, choose Page Setup from the File menu, and on the middle tab of
the dialog, choose Specific Printer. (Works in all versions except 2007,
where it is broken.)

If you want the user to be able to select a printer for the report, use the
Printer object (available in A2002 and later.) Details and example in:
Printer Selection Utility - Users assign printers to reports
at:
http://allenbrowne.com/AppPrintMgt.html
 
There is an example in VBA Help that shows exactly how to do this. Open help
and search for Printer
 
Allen,

Thanks for your help but that is not what I require. A bit more background.

I use PDFCreator to print reports and Word docs to PDFs. This changes the
printer from the default printer to PDFCreator, and then when it has
finished should switch back to the default printer. However occasionally
this fails.

As a failsafe I would therefore like to get the name of the default printer
using the Application.Printer object. If this is not possible I would like
to get the name of the currently selected printer. Then once PDFCreator has
finished doing it stuff I want to use the Application.Printer object to
switch back to the default printer (or previously selected printer).

Adrian
 
Klatuu,

Thanks. I have opened the VBA help and searched for Printer several times,
but have not found an example of how to do this.

Would you be able to copy and paste an example?

Thanks,

Adrian
 
What version of Access are you on?
If you are not on at least 2002, it is not available.
If you are on an earlier version, I don't know if or how it can be done.
Here is the code example from Help:

Dim prtDefault As Printer

Set Application.Printer = Application.Printers(0)

Set prtDefault = Application.Printer

With prtDefault
MsgBox "Device name: " & .DeviceName & vbCr _
& "Driver name: " & .DriverName & vbCr _
& "Port: " & .Port
End With
 
Dave,

Thanks.

I did see that code but Application.Printers(0) is the first printer in the
Printers collection, not the default printer.

Adrian.
 
I think you are a bit confused.

There are two properties invoved here

Printer is the current default printer
Printers is a collection of the printers available on the computer

The code example only shows the syntax of how you do it.

If you want to ensure a default printer stays the default after the PDF
printing, then you will need to save the name in a variable before you do
the pdf print and check to be sure after the pdf is complete:

Dim strDefPtr As String

strDefPtr = Application.Printer

Call PrintPDF

If Application.Printer.DeviceName <> strDefPtr Then
Application.Printer = Application.Printers(strDefPtr)
End If

Make more sense now?
 
I think you are a bit confused.

There are two properties invoved here

Printer is the current default printer
Printers is a collection of the printers available on the computer

The code example only shows the syntax of how you do it.

If you want to ensure a default printer stays the default after the PDF
printing, then you will need to save the name in a variable before you do
the pdf print and check to be sure after the pdf is complete:

Dim strDefPtr As String

strDefPtr = Application.Printer

Call PrintPDF

If Application.Printer.DeviceName <> strDefPtr Then
Application.Printer = Application.Printers(strDefPtr)
End If

Make more sense now?

Is it too late to ask another question on this thread? I am using the "Application.Printer" property to learn the default printer in my PC. However, it only always returns the last printer in the list every time (as if I typed "Application.Printers(0)", but I did not), no matter whether I change my default printers on my PC.
 
Back
Top