Solved

Find Default Printer

Posted on 2007-04-04
10
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

740 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