Solved

Access 2007 VBA - dynamic hyperlinks

Posted on 2011-03-01
4
509 Views
Last Modified: 2012-05-11
I've got a report that is supposed to show a listing of files.  This listing of files is contained within a table in my database and I have the data coming down to the report correctly.  I have a file name and path to the file on the computer or network where the file is located.  I would like to display only the name of the file and then when someone clicks on the file name it open the file for them.  I'm inside the onclick event of a textbox in the detail portion of the report that is showing the file name.  The textbox is set to appear as a hyperlink.  In code, when this textbox is clicked, how do I access the location field of the same record from the database.  Again, the location field is already part of the report.  The data is present, I'm just now sure how to access the right location (or path) for a given filename that has been clicked on.

Thanks.
0
Comment
Question by:JosephEricDavis
  • 3
4 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 35009544
What are the control/field names on your report?
OM Gang
0
 
LVL 7

Author Comment

by:JosephEricDavis
ID: 35009573
The field in the current record that I'm trying to access is called Location.
0
 
LVL 28

Accepted Solution

by:
omgang earned 500 total points
ID: 35009660
So, you have a text box for the file name and a text box/field for Location.

Private Sub FileName_Click()
On Error GoTo Err_FileName_Click

    Dim strLink As String
    strLink = Me.Location & Me.FileName
    Application.FollowHyperlink strLink, , True     '<--- use True to open in a new window, False to open in same window

Exit_FileName_Click:
    Exit Sub

Err_FileName_Click:
    MsgBox Err.Number & ", " & Err.Description, , "Error"
    Resume Exit_FileName_Click

End Sub

OM Gang
0
 
LVL 28

Expert Comment

by:omgang
ID: 35009674
You may need to tweak the link string a bit, e.g. if your location field contains
c:\myfolder\subfolder

and the FileName field contains
mysheet.xls

You'll need to do this
strLink = Me.Location & "\" & Me.FileName

OM Gang
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now