Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

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

Within Microsoft Access VBA, if I want to remove an error completely from memory do I use Err = 0 or Err.Clear?

0
stephenlecomptejr
Asked:
stephenlecomptejr
3 Solutions
 
athomsfereCommented:
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.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)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).
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:

 Either will work.

Jim.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
 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.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)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
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
 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.

 
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)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
0
 
stephenlecomptejrAuthor Commented:
Thanks for all the great replies!
I appreciate the comments.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now