By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,965 Members | 1,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,965 IT Pros & Developers. It's quick & easy.

Macro to open documents

P: 5
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!
Jun 11 '09 #1
Share this Question
Share on Google+
7 Replies

P: 167
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
Jun 12 '09 #2

P: 5
Thanks! I think this will work for me once I figure out how to correct some errors I keep getting.
Jun 12 '09 #3

Expert 5K+
P: 8,679
  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 cmdOpenHyperlink.
  5. In the Click() Event of cmdOpenHyperlink, you can write the following code which will enable Navigation to the Item currently Highlighted in lstHyperlinks in a New Window (True Argument):
    Expand|Select|Wrap|Line Numbers
    1. Private Sub cmdOpenHyperlink_Click()
    2. On Error GoTo Err_cmdOpenHyperlink_Click
    3. Dim lst As ListBox
    4. Dim strHyperlinkAddr As String
    6. Set lst = Me![lstHyperlinks]
    8. If lst.ItemsSelected.Count > 0 Then
    9.   strHyperlinkAddr = HyperlinkPart(lst, acFullAddress) & "#" & _
    10.                      HyperlinkPart(lst, acFullAddress)
    11.   Application.FollowHyperlink strHyperlinkAddr, , True
    12. End If
    14. Exit_cmdOpenHyperlink_Click:
    15.   Exit Sub
    17. Err_cmdOpenHyperlink_Click:
    18.   MsgBox Err.Description, vbExclamation, "Error Navigating to Hyperlink"
    19.   Resume Exit_cmdOpenHyperlink_Click
    20. End Sub
Jun 12 '09 #4

P: 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!
Jun 22 '09 #5

P: 5
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!
Jun 30 '09 #6

Expert 5K+
P: 8,679
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...
Jun 30 '09 #7

P: 5
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!
Jun 30 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.