?
Solved

Access 2007 VBA - dynamic hyperlinks

Posted on 2011-03-01
4
Medium Priority
?
538 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…
Suggested Courses

777 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