choose a specifc printer (pdf) with code
Hi, I would like to know if someone can give me a code (VB or VBA) to use in a MS Access 97 form to print a report to a specific printer. Basically I want to send a report to the pdf printer (to save the document as an Adobe pdf document). I realize I can choose my default printer from the Windows Control Panel, but I was hoping to be able to do this through code and not reset my default printer. Any suggestions? Thanks!
Tom
Re: choose a specifc printer (pdf) with code
This should get you started.
VB Code:
Sub ThomasJoPrinter()
Dim pPrinterCheck As Printer
Dim pCurrent As Printer
Dim bFound As Boolean
'Record the current default printer
Set pCurrent = Application.Printer
'Loop through all printers
'looking for Acrobat Distiller
For Each pPrinterCheck In Application.Printers
If pPrinterCheck.DeviceName = "Acrobat Distiller" Then
'Make Acrobat the default printer
Application.Printer = pPrinterCheck
'record the fact that it was found
bFound = True
Exit For
End If
Next pPrinterCheck
'if Acrobat was found then print to it
If bFound Then
DoCmd.OpenReport "Prod_hier", acViewNormal, "", "", acNormal
'Reset the default printer
Application.Printer = pCurrent
End If
End Sub
Re: choose a specifc printer (pdf) with code
Thanks, this looked like it should have worked but when I ran it, I got a "compile error", "User-defined, type not defined" on this:
Dim pPrinterCheck As Printer
I assume "Prod_hier" was to be replaced by the actual report name (called "PMIReport"). Is that assumption correct?
DoCmd.OpenReport "Prod_hier", acViewNormal, "", "", acNormal
Re: choose a specifc printer (pdf) with code
Hmmm the printer object is part of the Object Model for Access2003. I can't believe that it wasn't there in 97.
Can you open the Object Browser in the VBEditor (F2) and search for the Printer object?
Re: choose a specifc printer (pdf) with code
Did a search and got "none found". Only thing even close was:
Access OldConstants A_PRINTALL
ALSO:
acCmdPrint, acCmdPrintPreview, acCmdQuickPrint, acPrintAll
But nothing for a Printer :-(