[AccessD] Changing Default Printer

paul.hartland at fsmail.net paul.hartland at fsmail.net
Wed Aug 8 03:39:49 CDT 2007


Rocky,

Not the neatest code in the world, but works for me:

    Dim prnPrinter As Printer
    Dim strDeviceName As String
    Dim bolFoundPrinter As Boolean
    
    strDeviceName = Printer.DeviceName    ' Store current default printer
    bolFoundPrinter = False
    For Each prnPrinter In Printers
        If (prnPrinter.DeviceName = "NewPrinterName") Then
            Set Printer = prnPrinter
            bolFoundPrinter = True
            
            ' DO WHAT YOU WANT HERE TO PRINT
            
            Exit For
        End If
    Next
    ' Change back to original default printer
    For Each prnPrinter In Printers
        If (prnPrinter.DeviceName = strDeviceName) Then
            Set Printer = prnPrinter
            Exit For
        End If
    Next


this is in VB6, so I assume should work in VBA for Access



Message Received: Aug 07 2007, 08:49 PM
From: "Rocky Smolin at Beach Access Software" 
To: "'Access Developers discussion and problem solving'" 
Cc: 
Subject: [AccessD] Changing Default Printer


Dear List:

Slightly different request for changing printers to the one I had a few day
ago:

Is there an easy way to save the current windows default printer and change
to a user pre-selected printer (name stored in an local options table)?

This is for a distributable app so there's no way to know what the installed
printers are. The program needs to print to a PDF file. So the user has to
have a PDF printer installed. They pre-select it through a combo box on a
control panel loaded with all the installed printer names and the printer
name is saved in a local table. The app then runs at night without user
intervention triggered by windows scheduler. So when it runs these reports,
I need it to change the windows default printer to whatever printer they
select. And then change it back after I'm done printing.

MTIA

Rocky






-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





Paul Hartland
paul.hartland at fsmail.net
07730 523179


More information about the AccessD mailing list