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

gojets1721

Registered User.
Local time
Today, 05:53
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
Today, 04:53
Joined
Mar 9, 2014
Messages
5,423
If Err.Number = 2001 Or Err.Number = 3043 Then
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:53
Joined
Feb 19, 2002
Messages
42,970
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
Today, 08:53
Joined
Feb 19, 2002
Messages
42,970
It's an easy mistake to make. People do it all the time.
 

Users who are viewing this thread

Top Bottom