Results 1 to 4 of 4
  1. #1
    BudMan is offline Novice
    Windows 11 Office 365
    Join Date
    Nov 2014
    Location
    Stem, NC USA
    Posts
    23

    Question PDF Files as Attachments


    I was told it was not supported, but I thought I would double check first. In one of my databases, I often need to attach PDF files. Unfortunately, these files do not print when I print out the report. Is there any way to accomplish this? I find it rather strange that MS doesn't support PDF files natively. On a few occasions, I was forced to convert the PDF to a PNG file in order to get the report printed out as intended.

    Thanks!

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,422
    Best advice I can give you is never store files in an Access db even though you can. It can soon make your db approach the file size limit and IIRC you would never be able to upgrade to any version of sql server should the need arise. What you do is, have a table field that stores the path to the file. When user wants to see it, the file is opened by its native app by default. Storing the paths is made easier by using msoFileDialogFilePicker to pick a file. That dialog behaves a lot like Windows File Explorer dialog.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You can embed a linked PDF as page source in a report if that is what you are trying to achieve?
    But you would have to change the source path in VBA if it changed dynamically based on different reporting criteria, so I'm not completely clear on the requirement?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    dont embed pdfs, they look like crap.
    best to store the PATH then add a button to open it using: OpenNativeApp txtBox

    paste this into a module
    it will open ANY document in its native application.

    Code:
    #If Win64 Then      'Public Dclare PtrSafe Function
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #else
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function
    
    

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Adding attachments to email, saving attachments
    By snsmith in forum Programming
    Replies: 31
    Last Post: 09-10-2021, 08:25 AM
  2. Batch loading of attachments (jpeg files)
    By zkrucz in forum Programming
    Replies: 10
    Last Post: 10-17-2016, 11:34 AM
  3. Replies: 9
    Last Post: 01-26-2015, 01:58 PM
  4. Replies: 2
    Last Post: 01-29-2014, 03:19 PM
  5. Replies: 1
    Last Post: 02-21-2011, 09:55 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums