Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2013
    Posts
    3

    Unanswered: Button in Access to open specific PDF file

    Help with Access 2010 and Adobe X
    Im trying to create a button on an Access form, that when clicked opens a specific Adobe file based on information in a text box. The form displays only one record at a time. The field contains only a purhcase order number such as 150368. The Adobe file of this purchase order is named 150368.pdf.

    Form name: POinquiryFrm
    Based on table: POinfoTbl
    Field name: PONumber
    Location of Adobe files: L:\Facilities\Financials\Purchase Orders\ ******.PDF

    Thanks for the help,
    Jeff

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Do you want to open the pdf file inside Access (on a Form or a Report) or externally ?
    Have a nice day!

  3. #3
    Join Date
    Mar 2013
    Posts
    3
    Hi Sinndho, thanks for the reply. Externally would be fine. I just want the user to be able to look at a copy of thier purchase order and maybe print it if they want to. Then when they are done looking at it they can close Adobe and they are back in Access on the PO inquiry form. Thanks, Jeff

  4. #4
    Join Date
    Mar 2013
    Posts
    26
    I had the same task and figured out I could do it using this code tweaked from the google maps hyperlink code (search for it for more info if required). It works perfectly as long as your files are named exactly after the info in the feild boxes. You could remove some of the fields if you want to simplify the code.

    Function OpenPDF(Folder, File)

    Dim strAddress As String
    strAddress = Nz(Folder)
    strAddress = strAddress & IIf(strAddress = "", "", "/") & Nz(File)
    strAddress = strAddress & IIf(strAddress = "", "", ".pdf")
    If strAddress = "" Then
    MsgBox "There is no text to search."
    Else
    Application.FollowHyperlink "C:\Users\MyDocs\Pictures\" & strAddress
    End If

    End Function

    Also create a click event as follows
    Explanation: the address parts are in my table.
    A Click event is enabled via a macro with three Actions: (1 “optional”) MsgBox ="To
    use this functionality the database must be trusted." & Chr(13) & Chr(10) &
    "If you see the 'Security Warning' bar above, click 'Options' and then
    'Enable this content.'"
    (2) StopMacro
    (3) RunCode
    OpenPDF([Folder],[File])

    You will need to mess about with the fields to suit your folders and files.
    Last edited by kerrmuir; 03-28-13 at 16:13.

  5. #5
    Join Date
    Mar 2013
    Posts
    3
    Thanks Kerrmuir, I will give this a try. I appreciate the response. I'll let you know how it works out.

  6. #6
    Join Date
    Mar 2013
    Posts
    26
    Quote Originally Posted by woodpecker88 View Post
    Thanks Kerrmuir, I will give this a try. I appreciate the response. I'll let you know how it works out.

    Please do that, I would like to know that its helped someone out.
    Or let me know if you need more advice.

    copy the code again as there was an error in it. I have edited it to correct it.
    = "", """.pdf") was wrong and should be = "", "", ".pdf")

    Sincere appologies.
    Last edited by kerrmuir; 03-28-13 at 16:17. Reason: Code was wrong.

  7. #7
    Join Date
    Mar 2013
    Posts
    26
    I have also added an error handler when there is no file of that name fould.

    Function OpenPDF(Folder, File)

    On Error GoTo EndNow

    Dim strAddress As String
    strAddress = Nz(Folder)
    strAddress = strAddress & IIf(strAddress = "", "", "/") & Nz(File)
    strAddress = strAddress & IIf(strAddress = "", "", ".pdf")
    If strAddress = "" Then
    MsgBox "There is no text to search."
    Else
    Application.FollowHyperlink "C:\Users\MyDocs\Pictures\" & strAddress
    End If

    Exit Function
    EndNow:
    MsgBox "There is no PDF", vbInformation, "No PDF Found!"

    End Function

  8. #8
    Join Date
    Mar 2013
    Posts
    26
    Instead of error trapping code you could use this, thanks to Sinndho

    Code:
    If strAddress = "" Then
    MsgBox "There is no address to map."
    ElseIf Len(Dir(strAddress)) = 0 Then
    MsgBox "There is no PDF", vbInformation, "No PDF Found!"
    Else
    Application.FollowHyperlink "C:\Users\MyDocs\Pictures\" & strAddress
    End If

  9. #9
    Join Date
    Oct 2013
    Posts
    163
    Hi Kerrmuir,

    I am new user to Access. I had tried the above code to open a PDF file saved in server, however I am not ended in succeed. Could you please explain me in details.

    I just want to see the hyperlinks in query not in forms.

    Thanks and Regard
    R. Vadivelan

  10. #10
    Join Date
    Oct 2013
    Posts
    163
    Hi Members,

    With reference to my above post, I had imported the hyperlinks from Excel to Access. Initially It didn't work however after goggling I find out a way to create a hyperlinks in tables. Now the hyperlink works fine.

    But in the tables I am getting the full Hyperlink path as follows

    D:\01_Projects\05_FLNG Indonesia\DCC\TR to CPY\PIMS PDF Transmittal\AF09A-SAI-INM-TR-0178.pdf

    Is there any way to short display the same. (i.e.) I don't want to display the all the path, may be I would like to see only the number "0178"

    Kindly help me to sort out this issue.

    D:\01_Projects\05_FLNG Indonesia\DCC\TR to CPY\PIMS PDF Transmittal\ - Path of my File Location

    AF09A-SAI-INM-TR-0178 - File name

    Thanks and Regards
    R. Vadivelan

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here are two functions to get the path part and the name part of a full path:
    Code:
    Option Compare Database
    Option Explicit
    
    Const c_Path As String = "D:\01_Projects\05_FLNG Indonesia\DCC\TR to CPY\PIMS PDF Transmittal\AF09A-SAI-INM-TR-0178.pdf"
    
    Function GetFilePath(ByVal FullPath As String) As String
    
        Dim x As Long
        
        x = InStrRev(FullPath, "\")
        GetFilePath = Left(FullPath, x)
        
    End Function
    
    Function GetFileName(ByVal FullPath As String) As String
    
        Dim x As Long
        
        x = InStrRev(FullPath, "\")
        GetFileName = Right(FullPath, Len(FullPath) - x)
        
    End Function
    
    Sub Test()
    
        Debug.Print GetFilePath(c_Path)
        Debug.Print GetFileName(c_Path)
        
    End Sub
    Have a nice day!

  12. #12
    Join Date
    Oct 2013
    Posts
    163
    Dear Sinndho,

    Thanks for your quick reply. Since I am new user to Access, it is very difficult to understand for me. Herewith I had enclosed the sample table for your reference. This table I will import from excel every week. Initially I had used Hyperlink function in excel and imported to access but it not worked. Then I made some modifications and now the link works. However the hyperlink is displaying the full path.

    I would like to display the Hyperlink as "OPEN" or it will be better hyperlink displayed in the same field (Contractor CTR No). If I click the field then the corresponding PDF file should open.

    I had seen the videos for opening a form. I want to display the same way, however I don't want to display the form, I would like to open the PDF.

    Thanks and Regards
    R. Vadivelan
    Attached Files Attached Files

  13. #13
    Join Date
    Oct 2013
    Posts
    163
    Dear Seniors,

    Could anybody help me to sort out the above issue.

    It is quite urgent for me.

    Thanks and Regards
    R. Vadivelan

Posting Permissions

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