none
Print PDF with code in access2013 RRS feed

  • Question

  • Hi,i'm looking for the code to print a PDF file witch is like an attacment in the database.

     - If i print the report and there is a pdf file att. to the record it should print as well.

    can this be done?

    thanks

    Friday, March 24, 2017 2:47 AM

All replies

  • Hi Joske Vermeulen1,

    Currently there is no feature available with that you can directly print the attachment file when you print the report.

    please refer thread below. it is discussed for Access 2007, same thing will be apply for Access 2013.

    Printing attachments

    below is the response by the support engineer.

    The Attachment control was designed to only display the contents of certain image file formats.  Those formats are: *.bmp, *.emf, *.exif, *.gif, *.ico, *.jpeg, *.png , *.tiff and *.wmf.  If the file format is not one of those image formats, the control will check with the operating system for the icon associated with that extension, and then render that icon within the control.

    If you need the ability to print, the workarounds would be to either:

    1. use an OLE field - could lead to a large database if you have a lot of (or large) PDF files

    2. Adobe PDF Reader setup installs an ActiveX control for the reader. You could embed that control inside an Access report.  The control seems to expose a bunch of methods in its object model, and you could write VBA code to load a PDF file into the control.  It looks like the Load method does load a PDF and display the contents within the control frame.

    Given the popularity of PDF files I do think that we (Microsoft) should consider adding *.pdf to the list of supported file types.  I am going to submit this feedback to see if the developers will look at adding this functionality to future versions of the product. 

    you can also try to submit your feedback to User Voice.

    Access User Voice

    if they get enough response regarding this feature then Access Engineers try to add this feature.

    till then as a work around , you can try to use code below to print attachment file.

    Option Explicit 
     
    Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ 
    ByVal hwnd As Long, _ 
    ByVal lpOperation As String, _ 
    ByVal lpFile As String, _ 
    ByVal lpParameters As String, _ 
    ByVal lpDirectory As String, _ 
    ByVal nShowCmd As Long) _ 
    As Long 
     
    Public Sub PrintFile(ByVal strPathAndFilename As String) 
         
        Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0) 
         
    End Sub 
     
    Sub Test() 
         
        PrintFile ("C:\Test.pdf") 
         
    End Sub 
    
    

    you can try to modify the code as per your requirement.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 2:21 AM
    Moderator
  • Hi,

    I think one important thing to note with either suggestions is you'll have to extract the PDF file from the Attachment field and temporarily store it on your hard drive before you can print it.

    Just my 2 cents...

    Monday, March 27, 2017 2:59 AM