I prefer to use the Case construct, instead of IF() in cases like this.
Code:
Private Sub Text0_BeforeUpdate(Cancel As Integer)
Dim MinNum As Long
Dim MaxNum As Long
Dim EnteredNum As Long
MinNum = 99999
MaxNum = 999999
' EnteredNum = Me.MO_ID
EnteredNum = Me.Text0
Select Case EnteredNum
'99999 < MO_ID < 999999
Case Is < MinNum, Is > MaxNum
'Outside the limits, so
msgbox ("You can not enter a MO number here!")
DoCmd.Close acForm, "Query Form"
DoCmd.OpenForm "Query Home"
Cancel = True
Case Else
'Inside the limits, so
msgbox ("Sample Code - Working Properly")
End Select
End Sub
However, you said
MO_ID is an
Integer field
and that the minimum number is GT 99,999 and the maximum number is LT 999,999.
Given that:
Integer variables are stored as 16-bit (2-byte) numbers ranging in value from -32,768 to 32,767
Long (long integer) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647
, shouldn't the field type for "MO_ID" be a Long Integer??? The code might execute, but the number couldn't be stored in an integer field.
I'm just sayin........