ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   REPOST: How to handle errors (https://www.excelbanter.com/excel-programming/273848-re-repost-how-handle-errors.html)

Bruccce

REPOST: How to handle errors
 
I have tried this and it does not work... the reason is that the error
message is always changing!
in the last few minutes, I got 3 diff error numbers.

How can I test if the error numbers are different each time?

Thnaks
Bruce



"Bruccce" wrote in message
news:WbSXa.71532$uu5.7694@sccrnsc04...
I have a userform that I use.
I have it sending emails (works very well thanks to all of you in this
group).
The problem I have is that if I have a dialog box open (example, I have a
contact open, of msmessanger is asking me to log in) I get an error: The
error is
"Run-time error '-659537915 (d8b04005)':
A dialog box is open. Close it and try again.
[end] [debug] [help]
and then when I press any button, the form closes.

what I would like to happen, is if this error occurs, I would get a text

box
saying, "You have a dialog box open, please close it and then retry" and
then it would allow me to retry sending the email -after I close the
offending box-, or when I press a [retry] button, it would automatically

try
to resend. I would like this to happen without closing out the form.

How can I trap and process error messages?

Thanks
Bruce





Bob Kilmer

REPOST: How to handle errors
 
Bruce,
I understand your dilemma. If you want your code to react to particular
error numbers, you have to know when you write the code what they will be.
You can sometimes learn this thru documentation (look up "error code",
"error number", "trappable errors" or similar phrases in documentation for
the system you are working on) or by trial-and-error (no pun intended -- in
development, try to create all possible error conditions, run your code, and
observe the results). What is often done is to write code and responses for
the error numbers that are known (ignoring some if appropriate) and respond
to the rest in a generic way by reporting the number, description and
source, or by passing them back to the calling routine. At least if you
catch every error, your code can decide what to do -- even if it is just to
tell the user that "I don't really know what happened, but something went
wrong and the application is going to recover as best as it can."

A sometimes useful feature for development or to include in the final
application is to have the application log errors to a file for later
analysis, whether they report them to the user or not.

The commented code I included in my previous post will report to the user
any error that occurs. You can include that in an Else block to report
unidentified errors either just for development or to include in the
released application.

Here is an example of an extended error handler.

ErrHandler:
If Err.Number = -659537915 Then
MsgBox "You have a dialog box open, please close it and then retry"
blnDialogClosed = True 'just for example, equiv to closing dialog
Resume Retry
ElseIf Err.Number = 12345 Then
'ignore this one
ElseIf Err.Number = 12121 Then
'do something here (or not) and
'continue on the next line of code
Resume Next
ElseIf Err.Number = 91011 Then
MsgBox "Another error message. " & _
"Number: " & Err.Number & vbNewLine & _
"Description: " & Err.Description & vbNewLine & _
"Source: " & Err.Source
Else 'for other, unanticipated errors
MsgBox "Something bad happened. & _
"Please report this to Bruce." & vbNewLine & _
"Number: " & Err.Number & vbNewLine & _
"Description: " & Err.Description & vbNewLine & _
"Source: " & Err.Source
End If

--
Bob Kilmer


"Bruccce" wrote in message
news:YYwYa.90553$YN5.64295@sccrnsc01...
I have tried this and it does not work... the reason is that the error
message is always changing!
in the last few minutes, I got 3 diff error numbers.

How can I test if the error numbers are different each time?

Thnaks
Bruce



"Bruccce" wrote in message
news:WbSXa.71532$uu5.7694@sccrnsc04...
I have a userform that I use.
I have it sending emails (works very well thanks to all of you in this
group).
The problem I have is that if I have a dialog box open (example, I have

a
contact open, of msmessanger is asking me to log in) I get an error: The
error is
"Run-time error '-659537915 (d8b04005)':
A dialog box is open. Close it and try again.
[end] [debug] [help]
and then when I press any button, the form closes.

what I would like to happen, is if this error occurs, I would get a text

box
saying, "You have a dialog box open, please close it and then retry" and
then it would allow me to retry sending the email -after I close the
offending box-, or when I press a [retry] button, it would automatically

try
to resend. I would like this to happen without closing out the form.

How can I trap and process error messages?

Thanks
Bruce








All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com