Generic Error Handler Code?

D

Dave Elliott

Will this work for a generic error handler code fro my forms?
I am trying to trap some errors after making a mde.
If you close the form before it finishes Calculating, then I get errors ,
else it works fine.
This code is on my forms exit event.

If err <> 2501 Then
GoTo Err_Command500_Click:
End If
On Error GoTo Err_Command500_Click

Exit_Command500_Click:

Err_Command500_Click:
Exit Sub
 
S

stefan hoffmann

hi Dave,

Dave said:
This code is on my forms exit event.
If err <> 2501 Then
GoTo Err_Command500_Click:
End If
On Error GoTo Err_Command500_Click

Exit_Command500_Click:

Err_Command500_Click:
Exit Sub

Is this your exact code? You have to implement something like wait loop.

Private Sub Form_Exit()

On Local Error GoTo LocalError

'Your default exit code

Exit Sub

LocalError:
If Err.Number = 2501 Then
'if 2501 is your calculation indicator
Resume
Else
Resume Next
End If

End Sub

mfG
--> stefan <--
 
D

Dave Elliott

Thanks, however if I use this code as a mde app, then if the form tries to
close while still calculating, I get error messages.
The expression as the event property setting produced the following error:
Type Mismatch
The expression may not result in the name of a macro, the name of a user
defined function, or event procedure.
Three may have been an error evaluating the function, macro or code.
Is there anything I can do to resolve this?
 
S

stefan hoffmann

hi Dave,

Dave said:
The expression as the event property setting produced the following error:
Type Mismatch
The expression may not result in the name of a macro, the name of a user
defined function, or event procedure.
Is there anything I can do to resolve this?

Debug your code. Posting your code isn't a bad idea either.

mfG
--> stefan <--
 
A

Allen Browne

Dave, did you type this code into the property setting?

To use the code, set the property to:
[Event Procedure]
and then click the Build button (...) beside this.
Access opens a Code window, with the lines:
Private Sub Form_Exit()
End Sub
Whatever code you want goes between these 2 lines.

You only need error handling in the events where you have code. For those
events, you need code in each individual procedure. The code can call a
generic function to handle the error. That's an example of how to do that in
this article:
Error Handling in VBA
at:
http://members.iinet.net.au/~allenbrowne/ser-23a.html
 

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