dave said:
Access 2007
I want to have a macro that prints a form to .pdf.
However the .pdf printer is not the default printer.
Is there anyway to code changing printers?
This example assumes:
- You have the PDF add-in installed. If not, see
http://www.microsoft.com/downloads/...11-3E7E-4AE6-B059-A2E79ED87041&displaylang=en
- You want to save the PDF to your desktop.
- In older versions of Access, the code needs to just show a preview.
- You need to apply a filter (i.e. print one invoice, not all of them.)
- You want the pdf called "InvoiceXXX.pdf" where XXX is the invoice number.
Dim strFile As String
DoCmd.OpenReport "rptInvoice", acViewPreview, , "InvoiceID = " &
Me.InvoiceID
If Val(SysCmd(acSysCmdAccessVer)) >= 12# Then
strFile = Environ("HOMEDRIVE") & Environ("HOMEPATH") & _
"\Desktop\Invoice" & Me.InvoiceID & ".pdf"
DoCmd.OutputTo acOutputReport, strDoc, acFormatPDF, strFile, True
End If
If that's not what you want, it is possible to set the Printer object before
you open the report, and then reset it to Nothing again afterwards. If you
want to do that, see:
Printer Selection Utility - Users assign printers to reports
at:
http://allenbrowne.com/AppPrintMgt.html