none
vba Choosing a specific printer RRS feed

  • Question

  • I have an old database I'm using and there's a form that lets us print to pdf. However, this chooses adobes pdf printer which is always super slow. In my manual tests when I try to print something to adobe pdf vs the Microsoft Print to pdf. It's literally minutes slower with adobe.

    Regarding my form in question, I've found the code behind the button which I've pasted below.

    My question is, what value would in place of "Adobe" and "Acrobat", in order to use the Microsoft Print to PDF?

    Thanks!

        Select Case fre_PrinterOpt.value
            Case PRN_DEFAULT
                Call UTLOpenReport("rptDropShipInvoce-batch", , , sSQL)
                
            Case PRN_PDF
                sPrinter(0) = "Adobe"
                sPrinter(1) = "Acrobat"
                Call CreatePDF_FAX("rptDropShipInvoce-batch", sSQL, sPrinter())
                
            Case PRN_FAX
                sPrinter(0) = "Fax"
                sPrinter(1) = "FAX"
                Call CreatePDF_FAX("rptDropShipInvoce-batch", sSQL, sPrinter())
                
        End Select

    Wednesday, March 13, 2019 7:21 PM

Answers

  • You don't give us the body of the function CreatePDF_FAX(), so I can only guess what it does.  However, it's possible that it goes through the list of installed printers until it finds one whose name contains any of the strings in the array argument sPrinter.  If that's the case, you might try "PDF" (or "Microsoft Print to PDF") instead of "Adobe", or before "Adobe" in the array.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ZenMasta Friday, March 15, 2019 4:36 PM
    Thursday, March 14, 2019 11:26 PM

All replies

  • What version of Access are you working with?

    Since 2007, Access natively can create PDFs, so why not simply use

    DoCmd.OutputTo 

    withthe acFormatPDF format


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Thursday, March 14, 2019 9:20 PM
  • We sub to o365 so I'm using whatever current version is mainstream in that regard. But this is a really old database that we only recently converted from .mdb (literally summer of last year) to .accdb.

    Also I'm not a developer myself, but savvy enough to poke my nose into certain things which I thought would potentially be trivial such as this code snippet.
    Thursday, March 14, 2019 9:37 PM
  • You don't give us the body of the function CreatePDF_FAX(), so I can only guess what it does.  However, it's possible that it goes through the list of installed printers until it finds one whose name contains any of the strings in the array argument sPrinter.  If that's the case, you might try "PDF" (or "Microsoft Print to PDF") instead of "Adobe", or before "Adobe" in the array.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    • Marked as answer by ZenMasta Friday, March 15, 2019 4:36 PM
    Thursday, March 14, 2019 11:26 PM
  • We sub to o365 so I'm using whatever current version is mainstream in that regard. But this is a really old database that we only recently converted from .mdb (literally summer of last year) to .accdb.

    Also I'm not a developer myself, but savvy enough to poke my nose into certain things which I thought would potentially be trivial such as this code snippet.

    In that case, I dump all that code and use the one liner DoCmd.OutputTo 

    DoCmd.OutputTo acOutputReport, "rptDropShipInvoce-batch", acFormatPDF, "C:\..\...\PDFFileName.PDF", , , , acExportQualityPrint


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Friday, March 15, 2019 12:29 AM
  • As Daniel has said, the simplest option is to replace the code with a single line calling the OutputTo method.  Note, however, that this does not support an equivalent of the OpenReport method's WhereCondition argument to filter the report.  I assume that you are printing the current record, in which case the report's RecordSource query would need to reference a control in the form, whose value will restrict the output to the current record.

    You might like to take a look at InvoicePDF.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    This little demo file illustrates how a report (invoice) can be output as a PDF file, or as an attachment to an email.  It also illustrates how multiple invoices can be output as a single or as multiple PDF files.


    Ken Sheridan, Stafford, England

    Friday, March 15, 2019 12:24 PM
  • You don't give us the body of the function CreatePDF_FAX(), so I can only guess what it does.  However, it's possible that it goes through the list of installed printers until it finds one whose name contains any of the strings in the array argument sPrinter.  If that's the case, you might try "PDF" (or "Microsoft Print to PDF") instead of "Adobe", or before "Adobe" in the array.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Changing both to "Microsoft Print to PDF" did the trick. Thank you.

    I'm not sure how to find out what CreatePDF_FAX does or how to find it globally. If I paste the code from the whole form, it's only listed in the 2 cases there.

    https://pastebin.com/sR7651ym


    Friday, March 15, 2019 4:36 PM
  • We sub to o365 so I'm using whatever current version is mainstream in that regard. But this is a really old database that we only recently converted from .mdb (literally summer of last year) to .accdb.

    Also I'm not a developer myself, but savvy enough to poke my nose into certain things which I thought would potentially be trivial such as this code snippet.

    In that case, I dump all that code and use the one liner DoCmd.OutputTo 

    DoCmd.OutputTo acOutputReport, "rptDropShipInvoce-batch", acFormatPDF, "C:\..\...\PDFFileName.PDF", , , , acExportQualityPrint


    Daniel Pineault, 2010-2018 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    I ended up just changing the printer name as Dirk suggested and it worked.

    I did at least try replacing all of the code between Select Case and End Select with your line, but it didn't seem do do anything. Possibly because of what Ken. But the whole code for this form is https://pastebin.com/sR7651ym


    • Edited by ZenMasta Friday, March 15, 2019 4:39 PM
    Friday, March 15, 2019 4:38 PM