Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008

    Unanswered: Printing a report to a set printer (not the system default)

    Hi there

    I have a button on a form which has the following code behind...

    DoCmd.OpenReport "rptEve", acNormal

    This prints the report to the default printer. Is there any way of sending it to a different printer, installed and connected to the machine?


  2. #2
    Join Date
    May 2005
    Nevada, USA
    Provided Answers: 6
    Look in Page Setup on the Page tab.

  3. #3
    Join Date
    Aug 2008
    Nice one - thanks pbaldy!
    Is there anyway to do it in the code?

    Basically, I want to send it to the physical printer, and to the PDF creator (which acts like a printer) which I have installed on the machine.


  4. #4
    Join Date
    Nov 2007
    Adelaide, South Australia
    There are APIs around that will let you create PDF files without having to use a print command at all. IF you use that then you can dodge the whole specific printer minefield completely.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!

    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Dec 2004
    Madison, WI
    Here's some old PDF printing code I found in my archives. It's something to get you started but you'll need to research this more. Note that using this code (ie. Set Application.Printer = Application.Printers("Adobe PDF")) you can also change the printer to another printer other than "Adobe PDF". Also note that to utilize the PDF driver, besides "Adobe PDF", it could be "Adobe Writer" or "Adobe Distiller" or "Acrobrat Writer" (I can't remember which one) but it depends on which PDF driver you are utilizing and version of PDF you have installed. Adobe has this frustrating thing where they change the PDF driver name with different versions of PDF (frustrating as h#@@.) I might not recommend using the "Adobe Distiller" driver as I've had problems using that driver in the past. I believe "Adobe PDF" was the best thing for me to use but yours will again be dependant upon what you have installed for creating PDFs. Hope this helps. I believe the "Leban" website has some more specific examples for outputting to a PDF file.

    Public Function RunReportAsPDF(prmRptName As String, prmPdfName As String, UniqueID As Integer) As Boolean

    ' Returns TRUE if a PDF file has been created

    Dim AdobeDevice As String
    Dim strDefaultPrinter As String

    'Find the Acrobat PDF device

    AdobeDevice = GetRegistryValue(HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Devices", "Adobe PDF")

    If AdobeDevice = "" Then ' The device was not found
    MsgBox "You must install Acrobat Writer before using this feature"
    RunReportAsPDF = False
    Exit Function
    End If

    ' get current default printer.
    strDefaultPrinter = Application.Printer.DeviceName

    Set Application.Printer = Application.Printers("Adobe PDF")

    'Create the Registry Key where Acrobat looks for a file name
    CreateNewRegistryKey HKEY_CURRENT_USER, "Software\Adobe\Acrobat Distiller\PrinterJobControl"

    'Put the output filename where Acrobat could find it
    SetRegistryValue HKEY_CURRENT_USER, "Software\Adobe\Acrobat Distiller\PrinterJobControl", Find_Exe_Name(CurrentDb.Name, CurrentDb.Name), prmPdfName

    On Error GoTo Err_handler

    'Run the report (Note : I amended this code to filter the report for the unique ID)
    DoCmd.OpenReport prmRptName, acViewNormal, , "[Unique_id] = " & UniqueID

    While Len(Dir(prmPdfName)) = 0 ' Wait for the PDF to actually exist

    RunReportAsPDF = True ' Mission accomplished!


    Set Application.Printer = Application.Printers(strDefaultPrinter) ' Restore default printer

    On Error GoTo 0

    Exit Function


    If Err.Number = 2501 Then ' The report did not run properly (ex NO DATA)
    RunReportAsPDF = False
    Resume Normal_Exit
    RunReportAsPDF = False ' The report did not run properly (anything else!)
    MsgBox "Unexpected error #" & Err.Number & " - " & Err.Description
    Resume Normal_Exit
    End If

    End Function
    Last edited by pkstormy; 10-30-08 at 02:19.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts