[AccessD] Changing Default Printer

Rocky Smolin at Beach Access Software rockysmolin at bchacc.com
Wed Aug 8 09:21:29 CDT 2007


What version of Access has that Printer object?  And that code would go into
the report in the load or open event?  The code I found that I posted
yesterday works in A2K3, it's real short, but does it at the OS level, which
is probably more sketchy than doing it inside Access itself. What to you
think?

Rocky





 	
	

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
paul.hartland at fsmail.net
Sent: Wednesday, August 08, 2007 1:40 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Changing Default Printer
Importance: High

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
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.8/941 - Release Date: 8/7/2007
4:06 PM
 




More information about the AccessD mailing list