Solved

Find Default Printer

Posted on 2007-04-04
10
267 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now