VBA help states
Disables any enabled error handler in the current procedure.
Why would I want to do that?
Where would I want to use it?
--
steve
On Error Goto ErrH:
{ CODE}
Then here you want the code to break rather than skip to the handling
procedure.
On Error GoTo 0
{ MORE CODE}
If an error occurs here, it will not be handled. Depending on your settings,
it will break and display the error.
I use this for debugging more than anything.
DM
"Sbell" <sb...@sunclipse.com> wrote in message
news:epqNS4wxCHA.2532@TK2MSFTNGP10...
Think of it the other way around: When an error occur and no error handler
is invoked, then a (sometimes) informative error message displayed. This is
the default behavior.
So. Writing code you may want to handle errors certain ways. For example:
On Error Resume Next
means "nevermind, just continue", and it has its great advantages for
certain tasks. Also, for another example:
On Error Goto LogMe
means just that, where LogMe might be a place in the code where errors are
logged into a database and the user is immediately fired.
Now: On Error Goto 0 turns those settings OFF again, and the application is
returning to its default behavior. Of course that is useful.
HTH. Best wishes Harald
"Sbell" <sb...@sunclipse.com> wrote in message
news:epqNS4wxCHA.2532@TK2MSFTNGP10...
Thanks for the quick feedback!
Guess I'll just stay away from this one and use standard error handling.
steve
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Thanks!
But I was under the impression that this turning error handling off.
Meaning that no more handling would occur (?)...
Tried using it a while back and everything got screwed up... Errors ceased
to be handled further along in the code. And couldn't get the code to back
up to a particular line.
What am I missing here?
steve
"Harald Staff" <harald...@eunet.no> wrote in message
news:#0bReGxxCHA.1656@TK2MSFTNGP09...
On Error Goto 0 means simply that no special error handling will
occur. That does NOT mean that errors won't occur. It means that
any error will cause the code to stop right then and there, raising
a run time error message. The actual syntax is a bit misleading.
It doesn't means that on an error the code goes somewhere. It is
effectively the same as "On Error Stop Right Now".
On Error Resume Next
effectively tells VBA to ignore an error and keep moving on. It is
up to the programmer to deal with whatever error may arise.
On Error Goto Label:
tells VBA to skip directly to the Label and then resume execution.
Within the code following Label, you can use Resume to send code
execution back to the line that cause the error (this assumes that
you've fixed the error via code), or Resume Next to go to the line
following the one that raised the error.
On Error Goto 0
tells VBA to stop right there at the error line and display a
message (or, if there is an On Error statement in a procedure that
called this procedure, go back to that procedures error handler).
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Sbell" <sb...@sunclipse.com> wrote in message
news:elXGOPxxCHA.1296@TK2MSFTNGP11...
So what would that be then ? Crash the application ? Ignore any error ? It
should behave like "ignore my previous instructions on errors" and prompt
them with corresponding serial numbers and the works. But I can't tell what
happened/happens. Subs seem to inherit error handling instructions from
eachother in ways that I haven't found sufficient time to investigate and am
too stupid to fully understand. So theory this is, but it works for me. At
least I like to think it does <g>.
Best wishes Harald
Guess I'm going to have to play with this one and just "see" where it
takes me.
Some how the concept is eluding me.
All the other On Error ... types work just great for me.
Just this one...
Thanks for trying...
It isn't very complicated. An On Error statement controls how
errors are handled within the procedure in which it appears, AND
all procedures called by that procedure that do not have On Error
handlers of their own. For example, look at the following code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Top()
On Error GoTo EndTop:
Macro1
Macro2
Exit Sub
EndTop:
Debug.Print "Error Handler In Top"
End Sub
Sub Macro1()
On Error GoTo Macro1Err:
Debug.Print "M1"
Debug.Print 1 / 0 'raise an error
Exit Sub
Macro1Err:
Debug.Print "Error in Macro1"
End Sub
Sub Macro2()
' no error handler
Debug.Print "M2"
Debug.Print 1 / 0 'raise an error
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''
When Top executes, it sets up its error handler (On Error GoTo
EndTop:) and calls Macro1 and Macro2. This error handler traps
errors in Top itself and in Macro2, because Macro2 is called by Top
but does not have an error handler of its own. It doesn't control
errors in Macro1 because Macro1 has its own error handler.
So, when code execution enters Macro1, and 1/0 causes an error,
Macro1's error handler kicks in. Code returns to Top, then enters
Macro2. When 1/0 causes an error, Macro2 doesn't have an error
handler, so VBA looks upwards through the call stack, finds that
Top does have an error handler, so Top's error handler is used. An
error handler doesn't have to be in the calling procedure to be
invoked when an error is encountered in a called procedure. VBA
will search all the way up the call stack until it finds a
procedure with an error handler. If it finds one, it invokes it. If
it doesn't find one, a run time error stops code execution at the
line that caused the error.
Step through Top and you'll see how its error handler is called by
the 1/0 error in Macro2.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com
"Harald Staff" <harald...@eunet.no> wrote in message
news:ODwyxsxxCHA.1632@TK2MSFTNGP12...
Thanks Chip :-)
Best wishes Harald