How can I switch errors back On?

C

Chris K

I understand that Resume signifies where/when the execution process can
continue but does this also switch errors back on? - it's not specifically
mentioned in the help files
 
B

Bob Quintal

Seem to remember using

On Error Off

in the ol days but that doesn't work
From Access 2003 help for the on error statement:

On Error GoTo 0 Disables any enabled error handler in the current
procedure.
 
B

Bob Quintal

Seem to remember using

On Error Off

in the ol days but that doesn't work
From Access 2003 help for the on error statement:

On Error GoTo 0 Disables any enabled error handler in the current
procedure.
 
D

David W. Fenton

I understand that Resume signifies where/when the execution
process can continue but does this also switch errors back on? -
it's not specifically mentioned in the help files

As I answered your other post:

On Error GoTo 0

I would suggest you open the VBE, type "error" into the immediate
window and hit F1. You'll get a list of help topics, and you should
have a read through the On Error Statement help topic.

By the way, I think I sent my previous answer before finishing it --
I'd intended to say something about the VBE options that interact
with your error handling. In A2003, on the GENERAL tab of the VBE
Options dialog, there's an option group for ERROR TRAPPING. I always
set this to BREAK IN CLASS MODULE. This has always seemed
counterintuitive, since BREAK ON ALL ERRORS or BREAK ON UNHANDLED
ERRORS seem like the right choice, but if you do that, it doesn't
work right with class modules (it breaks on the call to the class
module instead of on the error within the class module causing the
error). If you click the HELP button and read the discussion of the
choices, it becomes clear which is the best choic, but I must say
this is a case where the choices only make sense after you've read
the detailed explanation.
 
D

David W. Fenton

Resume Next (in the error handler) is of limited use -- only if
you don't really care whether the faulting line worked or not.

Actually, if you have trapped for a specific error that you've
explicitly decided to ignore, that's a perfectly good reason for it.
Almost every case where someone posts code that uses On Error Resume
Next is one which, in my opinion, should be handled with an error
handler with a CASE SELECT that for the specific error number that
is being ignored passes control back to the next line.

This is bad:

On Error Resume Next
DoCmd.OpenReport "rptMyReport"
On Error GoTo 0
[do something else]

Say you're trapping for the NoData error (i.e., the report has no
data, and you've put Cancel = True in the report's OnNoData event)

On Error GoTo errHandler

DoCmd.OpenReport "rptMyReport"
[do something else]

exitRoutine:
Exit Sub

errHandler:
Select Case Err.Number
Case 2501 ' OpenReport cancelled
' ignore it
Resume Next
Case Else
MsgBox Err.Number & ": " & Err.Description, vbExclamation, _
"Error in OpenReport"
Resume exitRoutine
End Select

That's a case in which you specifically want to ignore one
particular error if it happens and continue on to the next line.
This is, in my opinion, the proper way to do it, i.e., using Resume
Next.
 

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