-
Access 2003 VBA - Change/Set Default Printer
I need to programmatically set/reset the default printer using Access 2003 VBA.
In searching around I found an example, but it doesn't work. This is what I'm trying
Code:
Dim prtDefault As Printer
Set Application.Printer = Application.Printers("\\ServerName\PrinterName")
Set prtDefault = Application.Printer
Ideally, of course, the actual printer name will be in a variable, but for testing purposes I'm actually hard coding it. Even hard coded, this code does not change the default printer.
I have a commondialog control on my Access 2003 form and I'm using the .ShowPrinter method. If I use that, and the user actually selects the desired printer, and clicks on the "Print" button, it does set the selected printer as default.
However, I need to do this behind the scenes (at least, that is my current requirement) with no user intervention.
-
Boyd Trimmell aka HiTech Coach
Microsoft MVP - Access Expert
[SIGPIC][/SIGPIC]
Office Programming 25+ years as a Software Developer specializing in:
Business Process Management
Accounting/Inventory Control
Customer Relations Management (CRM)
Electronic Data Interchange (EDI)
-
I've tried the sample code posted in the MSDN article.
I can get the default printer to switch to what I select. What I can't do is get it to reset itself based on a printer name I have saved in a variable.
-
I change the Access default printer regularly without any issues.
My first thought is that it has to do with what you are storing for the printer in a variable.
Would you please post all the VBA code you are using to do this.
Boyd Trimmell aka HiTech Coach
Microsoft MVP - Access Expert
[SIGPIC][/SIGPIC]
Office Programming 25+ years as a Software Developer specializing in:
Business Process Management
Accounting/Inventory Control
Customer Relations Management (CRM)
Electronic Data Interchange (EDI)
-
Put an actual server name and printer in this: \\ServerName\PrinterName
and the code in post number one is all the code I'm using to do this.
-
Ah ... I see your issue:
You are trying to use \\ServerName\PrinterNameand which does not work. You must use the device name (same as what displayed in the a print dialog's drop down list).
I will assume that you did not look at the example in the download link. Please take a look at that example if you have not done so.
Boyd Trimmell aka HiTech Coach
Microsoft MVP - Access Expert
[SIGPIC][/SIGPIC]
Office Programming 25+ years as a Software Developer specializing in:
Business Process Management
Accounting/Inventory Control
Customer Relations Management (CRM)
Electronic Data Interchange (EDI)
-
I ended up using the SetDefaultPrinter API
Code:
Option Compare Database
Option Explicit
Public Declare Function SetDefaultPrinter Lib "winspool.drv" _
Alias "SetDefaultPrinterA" (ByVal pszPrinter As String) As Long
Public myPrinter As String
Private Sub Form_Load()
myPrinter = Application.Printer.DeviceName 'grab default printer so we can reset it on exit
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetDefaultPrinter myPrinter 'reset to default
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|