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

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
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 

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