Solved

Find Default Printer

Posted on 2007-04-04
10
290 Views
Last Modified: 2013-11-27
Is there a way to find out which printer in the printers collection is currently set as the default printer?

This code will give me a list of the printers:
    For Each prtDefault In Application.Printers
        MsgBox prtDefault.DeviceName
    Next prtDefault

But it doesn't tell me which one is set as the default.

Thank you, stullhe104
0
Comment
Question by:stullhe104
  • 5
  • 4
10 Comments
 
LVL 12

Expert Comment

by:StuFox100
ID: 18849725
This is a VBscript that returns the default printer.
Cheers
Stu
----------------------
strComputer = "."

Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer Where Local = FALSE")
For Each objPrinter in colPrinters
    default_setting = objPrinter.default
    if default_setting then
        msgbox objPrinter.name
    end if
Next
0
 

Author Comment

by:stullhe104
ID: 18850274
Thanks for the info StuFox but I can't seem to find the right combination of libraries and code to make this solution work in MS Access 2003.

Does anyone know of a solution that will work in that environment?

0
 
LVL 39

Accepted Solution

by:
stevbe earned 125 total points
ID: 18856913
Application.Printer

returns the current default windows printer
you can then check the .Driver, .Port, etc. properties
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:stullhe104
ID: 18856925
Thanks steveb,
I did figure that out and I'm trying to use the following code to print an image of the MS Access form in landscape mode:
    Dim strDefaultPrinter As String
    strDefaultPrinter = Application.Printer.DeviceName
    Dim prtDefault As Printer
    Set prtDefault = Application.Printers(strDefaultPrinter)
    prtDefault.Orientation = acPRORLandscape
    DoCmd.PrintOut

Unfortunately it's not working. Do you see anything wrong with it?

Thanks, stullhe104
0
 
LVL 39

Expert Comment

by:stevbe
ID: 18856975
<Unfortunately it's not working.>
What is not working about it?
If you already found the answer then why did you accept my suggestion?
Why a B grade?
0
 

Author Comment

by:stullhe104
ID: 18856989
The switch to landscape orientation is not working, the form is printing portrait.
I accepted your suggestion becuase it is correct and does work.
Sorry about that, must have been a slip of the mouse button.
0
 
LVL 39

Expert Comment

by:stevbe
ID: 18857009
an easier ladscape solution would be to set the Page Setup (from the file menu) of the form to be landscape and then you could just DoCmd.Print and not have to mess with the printer at all.

Steve
0
 

Author Comment

by:stullhe104
ID: 18857132
But is there a way to do the Page Setup easily in code? Everything that I've read, including other posts that you have published, show this as a difficult task. DOCMD.DOMENUITEM is outdated and Runcommand acPageSetup doesn't work when a form is displayed.

Any ideas?
0
 
LVL 39

Expert Comment

by:stevbe
ID: 18857186
You set it up in design mode and then save the form. This way you only have to do it one time and there is no extra code. As for doing it through code when the app is running requires that you open the form in design mode. Any posts I have made that reference the difficulty in doing this is centered on the fact that this is impossible if your users only have the runtime of Access installed instead of the full version, it simply is a limitation of the runtime environment.

Steve
0
 

Author Comment

by:stullhe104
ID: 18857219
I can't believe I'm sitting here racking my brains out trying to write code to do something that was so simple. Sometimes you just need someone to point out that you are overcomplicating the issue!

Thanks Steve, your suggestion worked perfectly. Definitely an A+ solution!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question