Any idea why this error handling is being applied to all error codes? (1 Viewer)

gojets1721

Registered User.
Local time
Yesterday, 18:42
Joined
Jun 11, 2019
Messages
429
I have the below error handling code to apply only to two types of error codes, but it is applying to all.

Any idea why?

Code:
    If Err.Number = 2001 Or 3043 Then
        MsgBox "Erorr. Restart database."
    Else
        MsgBox "Error #" & Err.Number & " - " & Err.Description, , "Export Error"
    End If
   
    Resume btnSearch_Click_Exit
 

June7

AWF VIP
Local time
Yesterday, 17:42
Joined
Mar 9, 2014
Messages
5,470
If Err.Number = 2001 Or Err.Number = 3043 Then
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:42
Joined
Feb 19, 2002
Messages
43,260
Just to be clear. This expression:

If Err.Number = 2001 Or 3043 Then

Is evaluated as
If Err.Number = 2001 Or 3043 Is True Then

Since a number always tests true, the If is always true.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:42
Joined
Feb 19, 2002
Messages
43,260
It's an easy mistake to make. People do it all the time.
 

Users who are viewing this thread

Top Bottom