Solved

Find Default Printer

Posted on 2007-04-04
10
305 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

713 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