Results 1 to 5 of 5

Thread: choose a specifc printer (pdf) with code

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Location
    NJ
    Posts
    5

    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

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: choose a specifc printer (pdf) with code

    This should get you started.
    VB Code:
    1. Sub ThomasJoPrinter()
    2. Dim pPrinterCheck As Printer
    3. Dim pCurrent As Printer
    4. Dim bFound As Boolean
    5.    
    6.     'Record the current default printer
    7.     Set pCurrent = Application.Printer
    8.    
    9.     'Loop through all printers
    10.     'looking for Acrobat Distiller
    11.     For Each pPrinterCheck In Application.Printers
    12.         If pPrinterCheck.DeviceName = "Acrobat Distiller" Then
    13.             'Make Acrobat the default printer
    14.             Application.Printer = pPrinterCheck
    15.             'record the fact that it was found
    16.             bFound = True
    17.             Exit For
    18.         End If
    19.     Next pPrinterCheck
    20.    
    21.     'if Acrobat was found then print to it
    22.     If bFound Then
    23.         DoCmd.OpenReport "Prod_hier", acViewNormal, "", "", acNormal
    24.        
    25.         'Reset the default printer
    26.         Application.Printer = pCurrent
    27.     End If
    28.    
    29. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Location
    NJ
    Posts
    5

    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

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    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?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Location
    NJ
    Posts
    5

    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 :-(

Posting Permissions

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



Click Here to Expand Forum to Full Width