Macro to open documents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bbharris
    New Member
    • Jun 2009
    • 5

    Macro to open documents

    Hi!
    I am in need of some help with macros in an Access 2007 form. I have a table of document names that is linked to a list box in a form. All documents in the table have hyperlinks, so when a document name is clicked the correct document opens. This works fine. The users of the form will only have access to the form and not the table with hyperlinks, so I need for the users to be able to open any of the documents from the form. As of now, the hyperlinks do not appear in the form. I would like for users to be able to click a button beside the list box to open the document they have selected in the list box. However, I am not sure how to go about this. I hope this is clear.
    Thanks in advance!
  • hjozinovic
    New Member
    • Oct 2007
    • 167

    #2
    hi there,
    i was looking for the same solution today and i found this working example. It was great for me, so i hope it will help you too.
    Here is the link

    Comment

    • bbharris
      New Member
      • Jun 2009
      • 5

      #3
      Thanks! I think this will work for me once I figure out how to correct some errors I keep getting.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by bbharris
        Hi!
        I am in need of some help with macros in an Access 2007 form. I have a table of document names that is linked to a list box in a form. All documents in the table have hyperlinks, so when a document name is clicked the correct document opens. This works fine. The users of the form will only have access to the form and not the table with hyperlinks, so I need for the users to be able to open any of the documents from the form. As of now, the hyperlinks do not appear in the form. I would like for users to be able to click a button beside the list box to open the document they have selected in the list box. However, I am not sure how to go about this. I hope this is clear.
        Thanks in advance!
        1. Let's assume the List Box Name is lstHyperlinks.
        2. The Row Source for lstHyperlinks is a Single Field in a Table whose Data Type is Hyperlink.
        3. The MultiSelect Property of lstHyperlinks is = None.
        4. The Name of he Command Button to Navigate to the Highlighted Item in lstHyperlinks is cmdOpenHyperlin k.
        5. In the Click() Event of cmdOpenHyperlin k, you can write the following code which will enable Navigation to the Item currently Highlighted in lstHyperlinks in a New Window (True Argument):
          Code:
          Private Sub cmdOpenHyperlink_Click()
          On Error GoTo Err_cmdOpenHyperlink_Click
          Dim lst As ListBox
          Dim strHyperlinkAddr As String
          
          Set lst = Me![lstHyperlinks]
          
          If lst.ItemsSelected.Count > 0 Then
            strHyperlinkAddr = HyperlinkPart(lst, acFullAddress) & "#" & _
                               HyperlinkPart(lst, acFullAddress)
            Application.FollowHyperlink strHyperlinkAddr, , True
          End If
          
          Exit_cmdOpenHyperlink_Click:
            Exit Sub
          
          Err_cmdOpenHyperlink_Click:
            MsgBox Err.Description, vbExclamation, "Error Navigating to Hyperlink"
            Resume Exit_cmdOpenHyperlink_Click
          End Sub

        Comment

        • bbharris
          New Member
          • Jun 2009
          • 5

          #5
          Thank you so much! I have been out of town for the last week so I am just now able to get back to work on this. So far it is working, but if something comes up I will let you know. Again, thank you!

          Comment

          • bbharris
            New Member
            • Jun 2009
            • 5

            #6
            I just realized while testing the database that I left out some information that would affect this situation. I have a form that asks for the user's name. When the name is selected, a list box shows what disciplines that user falls under. The user then selects a discipline from the list box. A second list box will show what documents are associated with the discipline previously chosen. This list box is where the user selects the document to open. The code previously given works fine when testing as long as I do not select a user name or discipline because the code opens the hyperlink from the table with the hyperlinks. However, when a user name and discipline are selected, the document list is retrieved from a query and not a table. If someone could offer some advice on how to solve this I would greatly appreciate it!

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by bbharris
              I just realized while testing the database that I left out some information that would affect this situation. I have a form that asks for the user's name. When the name is selected, a list box shows what disciplines that user falls under. The user then selects a discipline from the list box. A second list box will show what documents are associated with the discipline previously chosen. This list box is where the user selects the document to open. The code previously given works fine when testing as long as I do not select a user name or discipline because the code opens the hyperlink from the table with the hyperlinks. However, when a user name and discipline are selected, the document list is retrieved from a query and not a table. If someone could offer some advice on how to solve this I would greatly appreciate it!
              Now, there are many more questions to be answered, such as:
              1. The Document Name is retrieved from a List Box, so what is the name of the List Box?
              2. Can Multiple Documents be selected within the List Box, and if so Open ALL the Documents at the same time?
              3. What are the Extensions for these Documents (*.doc, *.pdf, *.rtf, etc.)?
              4. etc...
              5. etc...
              6. etc...

              Comment

              • bbharris
                New Member
                • Jun 2009
                • 5

                #8
                Thanks for responding! I think I have figured this out. It was just a matter of moving some things around a little. So far it is working, but if not I will give you some more information to help get this working. Thanks again!

                Comment

                Working...