Hyperlink

U

umpty

I would like to programmatically set a hyperlink "Address"
property from within a word document. I have not been
successful thus far. Below is a snippet of code that I'm
using:

THE FOLLOWING IS WHAT I WOULD LIKE TO SET THE "ADDRESS" TO:
MyFileName1 = "Linked#NUREG-1801/" & docName & "#B" &
MyIdentifier & ""

Public Sub UpdateHyperlink()

Dim ws1 As DAO.Workspace
Dim db1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim MyFileName1 As String
Dim doc1 As Document
Set doc1 = ActiveDocument
Dim docName
Dim tempHyperlink As Hyperlink
docName = doc1.Name
MyFileName1 = "Linked#NUREG-1801/" & docName & "#B" &
MyIdentifier & ""
Set ws1 = CreateWorkspace("NewJetWorkspace", "admin", "",
dbUseJet)
Set db1 = ws1.OpenDatabase("C:\Gall\Update
Database\Gall2002.mdb")
Set rst1 = db1.OpenRecordset("Change Table", dbOpenDynaset)
rst1.FindFirst "tempSelect = 'Selected'"
If Not IsNull(rst1!tempSelect) Then
rst1.Edit
rst1!Hyperlink = "B" & MyIdentifier
(would i set the 'address' property here?
rst1.Update
End If

rst1.Close
Set rst1 = Nothing
db1.Close
Set db1 = Nothing
ws1.Close
Set ws1 = Nothing

End Sub
 
J

John Nurick

Hi Umpty,

You may have a problem here. # is a legal character in Windows
filenames, but in URLs it separates the name of the page or file from
the name of an anchor within it.

In the Access/Jet hyperlink field # is used to separate the (up to)
three HyperLinkParts, namely the displayed value, the address of the
document, and the (optional) named anchor, bookmark or whatever within
the document (the latter two parts corresponding to the URL). So if you
have filenames containing # you may be in trouble.

Assuming that's not the case, just build a string like this (for Word
documents)

Display Name#D:\Folder\File.doc#BookmarkName

and stuff it into the hyperlink field just like that; you don't need to
worry about setting the various HyperLinkParts separately.

For more portability, go the whole hog:

Display Name#file://server/share/Folder/File.doc#BookmarkName
 

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