trap hyperlink error

  • Thread starter Thread starter bobdydd
  • Start date Start date
B

bobdydd

Hi Everbody

I am trying to trap the error that SHOULD occur when there is no
internet connection.

Private Sub CmdPayHere_Click()
On Error GoTo Err_CmdPayHere_Click
Application.FollowHyperlink "http://www.microsoft.com"
Err_CmdPayHere_Click:
MsgBox "Page Not Available, Check that You ARE online",
vbInformation, "No Internet Connection"
End Sub

However, the above code displays the error message whether there is a
connection or not

Also, when there is NO CONNECTION, there is no error displayed at all.
All that happens is the browser does not display.

Thanks in advance for any help.

Bob
 
I am trying to trap the error that SHOULD occur
when there is no internet connection.
However, the above code displays the error message
whether there is a connection or not

See my inline VBA comments below:

Private Sub CmdPayHere_Click()

On Error GoTo Err_CmdPayHere_Click

Application.FollowHyperlink "http://www.microsoft.com"

' In normal operation, you must exit the sub before your
' error handler. Otherwise execution passes straight through
' and runs the code in your Error handler block.
Exit_CmdPayHere_Click:
Exit Sub

Err_CmdPayHere_Click:
MsgBox "Page Not Available, Check that You ARE online",
vbInformation, "No Internet Connection"

' I also like to do this. This way, my procedure has exactly
' one exit point and exactly one entry point. But some folks
' hate Goto's more than me:
Goto Exit_CmdPayHere_Click

End Sub

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
Before Err_CmdPayHere_Click: place these two lines:

Exit_CmdPayHere_Click:
Exit Sub

After the msgbox line, add the line
Resume Exit_CmdPayHere_Click

You could try trapping the error by changing your MsgBox prompt to something
like:
msgbox "Error #" & Err.Number & ", " & Err.Description

Then try to generate the error by proceeding with no connection. Note the
error # (let's say it's 9999), then do something like:

If Err.Number = 9999 Then
MsgBox "Page Not Available, Check that You ARE online"
Else
msgbox "Error #" & Err.Number & ", " & Err.Description
End If
Resume Exit_CmdPayHere_Click
 
Mike Labosh said:
' In normal operation, you must exit the sub before your
' error handler. Otherwise execution passes straight through
' and runs the code in your Error handler block.
Exit_CmdPayHere_Click:
Exit Sub

Err_CmdPayHere_Click:
MsgBox "Page Not Available, Check that You ARE online",
vbInformation, "No Internet Connection"

' I also like to do this. This way, my procedure has exactly
' one exit point and exactly one entry point. But some folks
' hate Goto's more than me:
Goto Exit_CmdPayHere_Click

Mike: Try using Resume Exit_CmdPayHere_Click. It ensures that the
application realizes that the error has been handled.

Good advice, btw.
 
Mike: Try using Resume Exit_CmdPayHere_Click. It ensures that the
application realizes that the error has been handled.

[slapping forehead] OOPS! Yes, because Resume also clears the error
condition. Can you tell it's been a while since I used VBA?

--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 
Back
Top