Solved

Access 2007 VBA - dynamic hyperlinks

Posted on 2011-03-01
4
501 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

911 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

20 Experts available now in Live!

Get 1:1 Help Now