VBA Error 0 (Zero) (1 Viewer)

SteveClarkson

Registered User.
Local time
Today, 19:54
Joined
Feb 1, 2003
Messages
439
Hello all,

I realise this is probably a really simple question to answer, but I can't find anything on it - doesn't help that you can't search this forum for either 0 or zero!!!

Anyway - periodically, when I have made up some error trapping code, I get error code 0 (zero) - it seems to indicate that everything is working OK - but obviously, I don't want this popping up all the time.

Yes, I can just add a little code to see if err=0, and to resume, but should I need to? I can't help but think I am doing something wrong!

Thanks!
 

RuralGuy

AWF VIP
Local time
Today, 13:54
Joined
Jul 2, 2005
Messages
13,826
I suspect you are doing something incorrectly, like not exiting your sub and dropping into your error handling code. If Err.Number = 0, there is *no* error!
 

seems_plausible

New member
Local time
Today, 15:54
Joined
May 31, 2011
Messages
1
If you just want to get rid of the error 0 message box can you just put an if statement around the message box such as:

If Err.number <> 0 Then
MsgBox "Error " & Err.number & " just occured."
End If
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 19:54
Joined
Sep 12, 2006
Messages
15,614
a) maybe your code is dropping into the error handler, instead of exiting before.

b) maybe you have used the on error routine, in which case you need accesserror, not error
 

boblarson

Smeghead
Local time
Today, 12:54
Joined
Jan 12, 2001
Messages
32,059
a) maybe your code is dropping into the error handler, instead of exiting before.
That is the most common error that people do. They don't put an exit point out of the procedure before the error handler like:

Code:
'...the rest of the function above
 
 
Exit_MyFunction:
   Exit Function
 
Err_Handler:
   MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
   Resume Exit_MyFunction
 
End Function
seems_plausible said:
If you just want to get rid of the error 0 message box can you just put an if statement around the message box such as:

If Err.number <> 0 Then
MsgBox "Error " & Err.number & " just occured."
End If
No need if a proper exit point is given.
 

ChrisO

Registered User.
Local time
Tomorrow, 06:54
Joined
Apr 30, 2003
Messages
3,202
A curious question…

While the answer given by Allan Bunch, and everyone else, is probably correct I can reproduce it another way: -
Code:
Sub TestIt()
    Dim X   As Long
    Dim Err As Long
    
    On Error GoTo ErrorHandler
    
    X = 1 / 0
    
ExitProcedure:
    Exit Sub

ErrorHandler:
    MsgBox Err
    Resume ExitProcedure

End Sub

So…
Dim Err As Long (in the same Procedure)
IOR
Private Err As Long (in the same Module)
IOR
Public Err As Long (in a standard Module)

can produce the the Err 0 if there is an error.
(IOR meaning that one, two or three of the above may exist and the nearest to the error will be used.)

In each case the declared Err variable is overloading the Public Err Object.
This means a user defined variable, even a Long, can take scope precedence over an Access Public Object.

Note:
Microsoft does not list ‘Err’ as a reserved word http://support.microsoft.com/kb/286335

However, Allen Browne http://allenbrowne.com/AppIssueBadWord.html does list it as a problem name.

In both cases ‘Err’ is implied to be a Function but it is not. It’s a public structure and can be overloaded by a user defined variable. In this case the variable would need to be dimensioned as Integer or Long. If the Err, Integer (or Long or Single or Double or Currency) is not assigned a value it will default to 0 (zero) and hence the value of 0 (zero) for a real error.

----------------------------

In any case, inadvertently dropping into the error handler is probably the cause but if it isn’t then check for a variable named ‘Err’.

Chris.
 

Users who are viewing this thread

Top Bottom