Solved

Access 2007 VBA - dynamic hyperlinks

Posted on 2011-03-01
4
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

695 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