Hyperlink as an Event - Automatically Kill if Run-time Error?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this code for a click event on a text field of mine. If there is no
web address in the box and you click on it by accident, it pops up the
run-time error of not being able to open Internet explore. How can you make
it kill it, so if it gets an error, just kills or stops trying so it wont pop
up an error message?

Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww

Thanks
Curtis
 
Easiest is an error routine, i.e.:

Sub whatever
On Error Goto handler
.....(rest of code)
Exit Sub
handler:
If Err.Number= (the number of your error) Then
Resume Next (or Exit Sub if there's nothing else that happens afterwards)
(any other errors can be captured with Else Ifs)
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub
 
Thanks Martin, sorry, would this be the code I need to put in there? I just
want it to do nothing if there is no url in there....

Private Sub Web_Site_Launcher_Click()
If Err.Number = 4 Then
Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww
End If
End Sub

Easiest is an error routine, i.e.:

Sub whatever
On Error Goto handler
....(rest of code)
Exit Sub
handler:
If Err.Number= (the number of your error) Then
Resume Next (or Exit Sub if there's nothing else that happens afterwards)
(any other errors can be captured with Else Ifs)
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub

Curtis Stevens said:
I have this code for a click event on a text field of mine. If there is no
web address in the box and you click on it by accident, it pops up the
run-time error of not being able to open Internet explore. How can you make
it kill it, so if it gets an error, just kills or stops trying so it wont pop
up an error message?

Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww

Thanks
Curtis
 
Nevermind, I got it!
----
On Error GoTo handler
Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww
Exit Sub
handler:
If Err.Number = 4 Then
Exit Sub
End If
End Sub
----

Thanks
Curtis

Thanks Martin, sorry, would this be the code I need to put in there? I just
want it to do nothing if there is no url in there....

Private Sub Web_Site_Launcher_Click()
If Err.Number = 4 Then
Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww
End If
End Sub

Easiest is an error routine, i.e.:

Sub whatever
On Error Goto handler
....(rest of code)
Exit Sub
handler:
If Err.Number= (the number of your error) Then
Resume Next (or Exit Sub if there's nothing else that happens afterwards)
(any other errors can be captured with Else Ifs)
Else
MsgBox Err.Number & " " & Err.Description
End If
End Sub

Curtis Stevens said:
I have this code for a click event on a text field of mine. If there is no
web address in the box and you click on it by accident, it pops up the
run-time error of not being able to open Internet explore. How can you make
it kill it, so if it gets an error, just kills or stops trying so it wont pop
up an error message?

Strwww = "http://" & [www]
Application.FollowHyperlink Address:=Strwww

Thanks
Curtis
 
Back
Top