Results 1 to 8 of 8
  1. #1
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29

    Open pdf file from Access form

    I have a form where I enter data about Cities (just an example). The user will be able to to pick a pdf file (for example history of the city) and add its location in the matching record. Then anyone reading the form will be able to open (from a simple command button) the proper file.
    City File
    London london.pdf
    Athens athens.pdf

    and so on...

    How can I do that?



    I need a browse button to help the user select the proper file and a command button. And I thinnk that the file should always be available in the same URL.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Do some research on

    Application.Followhyperlink .........location of your pdf file

    but other methods are available
    see http://www.utteraccess.com/wiki/inde...es_From_Access

  3. #3
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    I read a lot of links and I must admit I am kind of puzzled. So far the only suggestion that has almost worked is the one described here.

    I have done it and it succesfully opens the dialog box, it selects the file and it puts its path into the textbox. The only problem is that when I press on the hyperlink in the textbox, it does nothing instead of what I want: open the file.

    What can I do?

  4. #4
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    Sorry, I have to add one more problem with this solution: the file pathname doesn't remain when I reopen the form. I want it to stay there for other users to see and open if they like.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    This is a simple example of opening a pdf file using VBA

    Code:
    Sub Open_pdf()
    Dim str As String ' this is the path to the file
    str = "C:\Users\Jack\Documents\"  'path to .pdf
    Application.FollowHyperlink str & "NASCAROrderFeb122011.pdf"
    End Sub
    This will open the pdf file C:\Users\Jack\Documents\NASCAROrderFeb122011.pdf in a new browser window

  6. #6
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    But this means that I have to know in advance which file's path will be in the hyperlink. That's not what I'm looking for. I want the user to select from a browse box the file and then the hyperlink box will have its pathname available to select and open the file.

    Browser box: Select myfile.pdf
    Hyperlink box: Insert and save path to myfile.pdf

    Then the user, whenever he/she wants, can open the file through the hyperlink box.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    You want user to select a file with Windows file dialog browser and open a selected file? Try:
    Code:
    Private Sub cmdFileDialog_Click()
    ' Requires reference to Microsoft Office 1x.0 Object Library.
       Dim fDialog As Office.FileDialog
       Dim varFile As Variant
       ' Clear listbox contents.
       ''Me.FileList.RowSource = ""
       ' Set up the File Dialog.
       Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
       With fDialog
          ' Allow user to make multiple selections in dialog box
          ''.AllowMultiSelect = True
          .AllowMultiSelect = False
          ' Set the title of the dialog box.
          .Title = "Please select one or more files"
          ' Clear out the current filters, and add our own.
          .Filters.Clear
          .Filters.Add "Access Databases", "*.MDB"
          .Filters.Add "Access Projects", "*.ADP"
          .Filters.Add "All Files", "*.*"
          ' Show the dialog box. If the .Show method returns True, the
          ' user picked at least one file. If the .Show method returns
          ' False, the user clicked Cancel.
          If .Show = True Then
             ' Loop through each file selected and add it to our list box.
             For Each varFile In .SelectedItems
                ''Me.FileList.AddItem varFile
                Application.FollowHyperlink varFile
             Next
          Else
             MsgBox "You clicked Cancel in the file dialog box."
          End If
       End With
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    lios1984 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2012
    Posts
    29
    I have a problem with opening a FileDialog. It's asking me to register OLE server when I press ActiveXControls. The other day it was working...

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

Similar Threads

  1. Replies: 13
    Last Post: 10-12-2011, 12:48 PM
  2. Open a pdf file from Access
    By bginhb in forum Programming
    Replies: 5
    Last Post: 08-17-2011, 02:42 PM
  3. Replies: 4
    Last Post: 09-28-2010, 07:04 PM
  4. Replies: 1
    Last Post: 09-27-2010, 10:10 AM
  5. Replies: 1
    Last Post: 08-19-2009, 01:54 AM

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