Hyperlinks using code

B

Bruce M. Thompson

Is there a way to assign the hyperlink address of a field
using vba?

Assuming the field is defined as a "Hyperlink" data type, you can assign the
value the same way as any other field value. Try:

Me!HyperAddress = http://www.mvps.org/access/

Of course, you need to replace "HyperAddress" with the name of your field.
 
J

Jarod

When I used that it only puts the hyperlink address in
the value of the field. The value of the field and the
hyperlink address are not the same value. The user inputs
a file name and when he clicks add record it wil put the
filename as the value and attach a hyperlink to that
field. Is this possible?
 
B

Bruce M. Thompson

When I used that it only puts the hyperlink address in
the value of the field. The value of the field and the
hyperlink address are not the same value. The user inputs
a file name and when he clicks add record it wil put the
filename as the value and attach a hyperlink to that
field. Is this possible?

Oops! That wasn't the solution at all. Sorry. <grunt>

Look up "HyperlinkPart Method" in Access VBA Help. The "value" assigned to a
hyperlink field can contain a string to set the various properties of the
hyperlink and using the "HyperlinkPart Method", you can retrieve various parts
of the hyperlink in and modify the string that sets a new value. The example
below sets both the Display Text and the Hyperlink Address for the field
"HyperAddress":

'************EXAMPLE START
Dim strDelimiter As String
strDelimiter = "#"

Me.HyperAddress = "The Access Web" & strDelimiter _
& "http://www.mvps.org/access/" & strDelimiter
'************EXAMPLE END

To retrieve the "Address" part, you can use

strAddress = Application.HyperlinkPart(Me.HyperAddress,acAddress)

You can then edit the "Display Text" property for that hyperlink by using:

Me.HyperAddress = "The Wonderful Access Web" _
& strDelimiter & strAddress _
& strDelimiter

You can use the same technique to change the "Address" portion while maintaining
the same "Display Text".
 
Joined
May 29, 2016
Messages
2
Reaction score
0
I've tried Application.HyperlinkPart(Me.HyperAddress,acAddress) and a half dozen other varieties and the only thing that ever returns is just the file name. This is Access 2010. Nothing gives me the full URL text. Nothing gives anything except the filename. Any help out there?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top