Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Access Default Printer 1

Status
Not open for further replies.

scamquist58

Technical User
Dec 15, 2022
6
US
I am trying to change the default printer when an Access form loads.
The following code works:

Private Sub Form_Load()
Dim prtDefault As Printer
Set Application.Printer = Application.Printers(7)
Set prtDefault = Application.Printer
End Sub

However, I want to specify the printer name.

DEVICE NAME: \\PP-FP01\Office Cannon iR-ADV C3230i UFR II
DRIVER NAME: winspool
PORT: 192.168.0.25

Any ideas on how to use device name or port or whatever to accomplish this?
Thank you in advance.



When the form closes, it reverts back to the default using:
Private Sub Form_Unload(Cancel As Integer)
'~~>To restore the Printer object, to the Windows default
'~~> Tis destroys the object. MS Access then reconstructs it - from the default Windows printer.
Set Application.Printer = Nothing
End Sub
 
Printer can be called by index or device name.
Application.Printers.Count return number of printers.
Application.Printers(i) returns Printer, that, among others, can return DeviceName or DriverName.

combo
 
If I use any of the following statements:
Set Application.Printer = Application.Printers("\\PP-FP01\Office Cannon iR-ADV C3230i UFR II")
Set Application.Printer = Application.Printers("Office Cannon iR-ADV C3230i UFR II")
Set Application.Printer = Application.Printers("192.168.0.25")

I the the error:

Run-time error '5':
Invalid procedure call or argument
 
Any of [tt] Application.Printers(i).DeviceName[/tt] returns one of the three arguments in your examples?

combo
 
I tried

Set Application.Printer = Application.Printers(i)."192.168.0.25"
Set Application.Printer = Application.Printers(i)."\\PP-FP01\Office Cannon iR-ADV C3230i UFR II"
Set Application.Printer = Application.Printers(i)."\\PP-FP01\Office Cannon iR-ADV C3230i UFR II"

Returns
Complie error.
Expected: identifier or bracketed expression
 
The syntax is ok (i.e. Set Application.Printer = Application.Printers("Office Cannon iR-ADV C3230i UFR II") ). Probably none of arguments used is not a valid printer name in the system. Check names (Debug.Print Application.Printers(0).DeviceName and next ) in immediate window.

combo
 
From immediate window

Debug.Print Application.Printers(7).DeviceName
\\PP-FP01\Office Canon iR-ADV C3230i UFR II

full code that works
Private Sub Form_Load()
Dim prtDefault As Printer
Set Application.Printer = Application.Printers(7)
Set prtDefault = Application.Printer
End Sub

code below fails with
Complie error.
Expected: identifier or bracketed expression

Private Sub Form_Load()
Dim prtDefault As Printer
Set Application.Printer = Application.Printers(i)."\\PP-FP01\Office Canon iR-ADV C3230i UFR II"
Set prtDefault = Application.Printer
End Sub
 
The proper syntax:
Set Application.Printer = Application.Printers(("\\PP-FP01\Office Canon iR-ADV C3230i UFR II")

If not, does this work?:
Set Application.Printer = Application.Printers(Application.Printers(7).DeviceName)
If so, the spelling should be checked.


combo
 
Combo,
Thank you for the assistance.
This is the line that worked for me

Set Application.Printer = Application.Printers(("\\PP-FP01\Office Canon iR-ADV C3230i UFR II"))

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top