Get default printer name

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
 
A

Allen Browne

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
 
G

Guest

There is an example in VBA Help that shows exactly how to do this. Open help
and search for Printer
 
A

Adrian

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
 
A

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
 
G

Guest

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
 
A

Adrian

Dave,

Thanks.

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

Adrian.
 
G

Guest

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?
 
Joined
Jan 24, 2022
Messages
1
Reaction score
0
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.
 

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