Bullet-proofing the error sub.

mafhobb

Registered User.
Local time
Today, 11:32
Joined
Feb 28, 2006
Messages
1,249
Hello.

For a while I have been using the following code to call a sub and e-mail me all information about the errors that my db users encounter:
Code:
Form_Load_Error:
    Dim ErrorForm As String
    Dim ErrorControl As String
    Dim ErrorCode As String
    Dim ErrorNumber As String
    ErrorForm = Nz(Screen.ActiveForm.Name, "No Form Loaded")
    ErrorControl = Nz(Screen.ActiveControl.Name, "No Control Loaded")
    ErrorNumber = Err.Number
    ErrorCode = Err.Description
    Call SendError(ErrorCode, ErrorNumber, ErrorControl, ErrorForm)
    Exit Sub

This has been working well (that I know) so far, however today I was tweaking the code in a form and I happened to open the form directly to run some tests instead of doing it through another form. In any case, I noticed that when opening the form directly I get an error (which is expected because the code cannot perform some of the tasks it is requested to perform). This is "Runtime Error 2474. The expression you entered requires the control to be in the active window". As I say, this error is expected becasue the form was opened directly and it happens here:
Code:
   ErrorControl = Nz(Screen.ActiveControl.Name, "No Control Loaded")

My issue is that the error sub is in itself creating an error and when this happens, the code halts and this error is not getting recorded and it is not e-mailed to me.

I wonder now if there may be other instances where this may also happen and I am not aware of them.

How can the error sub be bullet-proofed?

Thanks

mafhobb
 
An error happens somewhere in the code because I do not load the form properly (as I say, this error was expected), but in the process of reporting the 1st error, the error sub itself comes up with an error.

Normally the first error won't happen because the form will be loaded properly, but now I wonder if there are any errors that do happen but do not get reported to me because the error sub itself comes up with an error because of the type of error that happens first.

What I am looking for is for expert advice on setting up a good error sub and opinions on what I have done, in an effort to improve it.

mafhobb
 
Code:
 ErrorControl = IIF(IsNull (Screen.ActiveControl), "No Control Loaded", Screen.ActiveControl.Name)

try that way for both form and control.
 
When you're loading it from another form, the error message will throw that form's name. You might want to find a way to better specify that sort of information.
 
mafhobb

So you are saying you are opening the form directly where you do not have any control active and you get an error message "no control loaded".

Well that might just be there is no control active. No?
 

Users who are viewing this thread

Back
Top Bottom