# Database Discussions > Microsoft Access >  Access 2003 VBA - Change/Set Default Printer

## Moe1950

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

```
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.

----------


## HiTechCoach

See:

Programming Printer Settings in Microsoft Access 2002

also download ODC_Acc10_Printers.exe

----------


## Moe1950

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.

----------


## HiTechCoach

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.

----------


## Moe1950

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.

----------


## HiTechCoach

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.

----------


## Moe1950

I ended up using the SetDefaultPrinter API

```
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
```

----------

