Have you ever changed the default printer from code?
I need to change the default printer and then change it back to the original printer.
Printable View
Have you ever changed the default printer from code?
I need to change the default printer and then change it back to the original printer.
I use this to set the printer on a till that prints receipts.
VB Code:
Dim pPrinter As Printer For Each pPrinter In Printers If pPrinter.DeviceName = gstrReportPrinter Then ' Set printer as system default. Set Printer = pPrinter ' Stop looking for a printer. Exit For End If Next
The gstrReportPrinter is a string that holds the name of the printer I want to use.
I loop through the availablre printers and when I find the one I want set the printer object to use that one
Hope this Helps.
The Printer Object is supported in VB, but not (to my knowledge) in VBA, so Gary's code is not going to work for you.
What is wrong with this code? I want it to print to Acrobat and not the default printer.
Code:Option Explicit
Private acc As Access.Application
Private Sub Command1_Click()
Dim pPrinter As Printer
Dim view As Long
Dim acdstl As String
acdstl = "Acrobat Distiller"
Set acc = New Access.Application
For Each pPrinter In Printers
If pPrinter.DeviceName = acdstl Then
' Set printer as system default.
Set Printer = pPrinter
' Stop looking for a printer.
Exit For
End If
Next
acc.OpenCurrentDatabase ("C:\Documents and Settings\ihayse\Desktop\Monthly\Member Reports.mdb")
acc.DoCmd.OpenReport "AB_Add-Drop by PCP Labels", acViewNormal 'acViewNormal means the report is just printed.
acc.CloseCurrentDatabase
Set acc = Nothing
End Sub
I got it.........
If you got it, post it....it could, and probably will, help someone else. :)
The code above will not print Access Reports. For some reason when it comes to print Access Reports they are going through the default printer. But if I say form1.printform it will send the form to the Distiller but not the Access Report.......
FYI
You can change the default printer for each and ever Access Report in the "Page Setup" of the report.....
Thanks! :D