Error handling

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

If Procedure1() calls Procedure2(), such as:

===============================
Sub Procedure1()

'........Do something here

Call Procedure2()

'........Do some more things here

End Sub
=================================

If I have error handling in Procedure2() that causes it to exit the
procedure on an error, what is the best way to ensure it exits Procedure1()
immediately without running any more code? I could put no error handling in
Procedure2(), and allow the errors to be handled by procedure1(), but I am
guessing there must be a better way.

Thanks for any help.

Adrian
 
If you raise an error in Procedure 2 (ErrRaise number[, source][,
description][, helpfile][, helpcontext]), the error handler in Procedure 1
will catch it, so that no more code in Procedure 1 will get run.
 
Doug,

I use the following code (an example) in Prtocedure2, which I add using the
MS VBA Error Code Handler add-in.

================================================================
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbCritical, "Form_frmTest.Procedure2"
End Select
================================================================

If there is an error in Procedure2 and I click 'OK' on the message box it
goes back to Procedure1 and continues running the code immediately after the
call to Procedure2. What am I doing wrong?

Thanks for your help.

Adrian



Douglas J. Steele said:
If you raise an error in Procedure 2 (ErrRaise number[, source][,
description][, helpfile][, helpcontext]), the error handler in Procedure 1
will catch it, so that no more code in Procedure 1 will get run.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Adrian said:
If Procedure1() calls Procedure2(), such as:

===============================
Sub Procedure1()

'........Do something here

Call Procedure2()

'........Do some more things here

End Sub
=================================

If I have error handling in Procedure2() that causes it to exit the
procedure on an error, what is the best way to ensure it exits Procedure1()
immediately without running any more code? I could put no error handling in
Procedure2(), and allow the errors to be handled by procedure1(), but I am
guessing there must be a better way.

Thanks for any help.

Adrian
 
One thing you're doing wrong is not reading my suggestion! I said to raise
an error in Procedure 2, not use a message box to report an error.

HandleErr:
Err.Raise Err.Number, "Form_frmTest.Procedure2", Err.Description

Assuming you have error checking in Procedure 1, it will now catch that
error.


--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Adrian said:
Doug,

I use the following code (an example) in Prtocedure2, which I add using the
MS VBA Error Code Handler add-in.

================================================================
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbCritical, "Form_frmTest.Procedure2"
End Select
================================================================

If there is an error in Procedure2 and I click 'OK' on the message box it
goes back to Procedure1 and continues running the code immediately after the
call to Procedure2. What am I doing wrong?

Thanks for your help.

Adrian



Douglas J. Steele said:
If you raise an error in Procedure 2 (ErrRaise number[, source][,
description][, helpfile][, helpcontext]), the error handler in Procedure 1
will catch it, so that no more code in Procedure 1 will get run.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



Adrian said:
If Procedure1() calls Procedure2(), such as:

===============================
Sub Procedure1()

'........Do something here

Call Procedure2()

'........Do some more things here

End Sub
=================================

If I have error handling in Procedure2() that causes it to exit the
procedure on an error, what is the best way to ensure it exits Procedure1()
immediately without running any more code? I could put no error
handling
in
Procedure2(), and allow the errors to be handled by procedure1(), but
I
 
Back
Top