Does err = 0 and err.Clear do the same thing?  Which one clears the error from the stack?

stephenlecomptejr
stephenlecomptejr used Ask the Experts™
on
Within Microsoft Access VBA, if I want to remove an error completely from memory do I use Err = 0 or Err.Clear?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
error 0 in most things (and Access as well) means success. So Err=0 means the action was successful. Err clear clears any level error including a success level error.

So no, they are not the same.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007
Commented:
Answer is No.

Err=0 as in

If Err.Number = 0 means No Error occurred.

From the Help File:
Clear Method
         

Clears all property settings of the Err object.

Syntax

object.Clear

The object is always the Err object.

Remarks

Use Clear to explicitly clear the Err object after an error has been handled, for example, when you use deferred error handling with On Error Resume Next. The Clear method is called automatically whenever any of the following statements is executed:

Any type of Resume statement
Exit Sub, Exit Function, Exit Property

===

On Error Goto 0   resets any error currently in effect.

mx


Any On Error statement
Note   The On Error Resume Next construct may be preferable to On Error GoTo when handling errors generated during access to other objects. Checking Err after each interaction with an object removes ambiguity about which object was accessed by the code. You can be sure which object placed the error code in Err.Number, as well as which object originally generated the error (the object specified in Err.Source).
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:

 Either will work.

Jim.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
 I just tested this and either will work, but err.clear is better.  

  Doing:

  Err = 0

  Doesn't clear the error object (ie. the last error description still remains).  However it will work as you would think for in-line error handling. i.e.

  On Error Resume Next
  Err = 0
  ' Do something
  If Err<>0 then
    ' Error occured
  End If

Jim.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
"  Doesn't clear the error object (ie. "
Then they are not the same.

"Use Clear to explicitly clear the Err object after an error has been handled, "

mx
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012
Commented:
 I don't think though that was the intent of the question.   Also you can't be positive that Err = 0 doesn't clear the stack.  Remember, doing Err = 0 has been around a lot longer then Err.Clear.  The error object wasn't introduced until Access 95 when VBA came along, so it's hard to say what Err = 0 actually does.  It doesn't clear the error object for sure, but I'm not sure about the stack.

 Wayne would know the answer to that for sure.

Jim.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
"so it's hard to say what Err = 0 actually does. "
Which is why I don't use it in this context.

Stephen ... if you want the ultimate error handler, then see this:

http://www.everythingaccess.com/vbwatchdog.htm

And lots of great info in this site ...

mx

Author

Commented:
Thanks for all the great replies!
I appreciate the comments.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial