Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

Find Default Printer

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
stullhe104
Asked:
stullhe104
  • 5
  • 4
1 Solution
 
StuFox100Commented:
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
 
stullhe104Author Commented:
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
 
stevbeCommented:
Application.Printer

returns the current default windows printer
you can then check the .Driver, .Port, etc. properties
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
stullhe104Author Commented:
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
 
stevbeCommented:
<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
 
stullhe104Author Commented:
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
 
stevbeCommented:
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
 
stullhe104Author Commented:
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
 
stevbeCommented:
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
 
stullhe104Author Commented:
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

Technology Partners: 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!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now