Urgent ! - Hypelink code works in 2003 not in 2000

  • Thread starter Thread starter Gordzilla
  • Start date Start date
G

Gordzilla

I developed a form for a user in Access 2003 works like a charm. He only
has 2000, told me after the fact! Upgrade is not option. Have to change my
forms to work.
The form has 4 command buttons on it that with a coresponding text box
hidden behind it. The command button is supposed to open a hyperlink to a
document, the hyperlink value is stored in the text box. If the text box is
empty, a prompt to add a new hyperlink opens. The user browses to the file
in question, selects it and the hyperlink is pasted into the textbox. When
the record is saved the hyperlink is stored in a hyperlink field in the data
source. In Access 2003 it all works. In access 2000, existing hyperlinks
work, new ones are added but when you try and open one you've added, it's
not recognized and the add prompt comes up. If you close access completely
and go back it all works and the hyperlink is in the table. Debugging has
led to beleive that the problem is with
Application.FollowHyperlink strInput, , True since it evals to false on a
new hyperlink, even if the record is saved, form closed, etc.

Code:
On Click event for button

Private Sub cmdDOC_link_Click()
Dim Response, MyString
On Error GoTo cmdDOC_link_Click_Error

If ValidLink(Me.txtDOC_Link) = False Then

Response = MsgBox("file not found. Would you like to add one now?",
vbYesNo, "Add Document")

If Response = vbYes Then ' User choose Yes.
txtDOC_Link.Visible = True ' text box to hold hyperlink
txtDOC_Link.SetFocus
DoCmd.RunCommand acCmdInsertHyperlink
cmdDOC_link.SetFocus
txtDOC_Link.Visible = False
Else ' User choose No.
MyString = "No" ' Perform some action.
End If
End If
Hyper_Colours
exit_cmdDOC_link_Click:
Exit Sub

cmdDOC_link_Click_Error:
If Err <> 2501 Then
MsgBox Err & ": " & Err.DESCRIPTION
Resume exit_cmdDOC_link_Click
End If

End Sub

Public Function ValidLink(strInput) As Boolean
'Dim strInput As String
On Error GoTo Error_ValidLink
Application.FollowHyperlink strInput, , True
ValidLink = True

Exit_ValidLink:
Exit Function

Error_ValidLink:
' MsgBox Err & ": " & Err.Description
ValidLink = False
Resume Exit_ValidLink
End Function
 
I think you're confusing hyperlink fields and URLs.

Application.FollowHyperlink wants a URL or a fully qualified filespec,
e.g.

Application.FollowHyperlink "http://www.bbc.co.uk"
Application.FollowHyperlink "C:\Temp\test.txt"

while a hyperlink field can contain a URL (with the http:// protocol
assumed if it's absent) or a filespec, with optional "display text" and
subaddress elements, e.g.
http://www.bbc.co.uk
www.bbc.co.uk
BBC#http://www.bbc.co.uk#

If you use the Insert Hyperlink dialog, it automatically generates both
display text and URL. By default the display text is the same as the
URL, e.g.
http://www.bbc.co.uk#http://www.bbc.co.uk#

Application.FollowHyperlink chokes on stuff like that. If you want to
use Application.FollowHyperlink on the contents of a hyperlink field,
parse the URL out of the field (e.g. with the HyperLinkPart() function).
 

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

Back
Top