Restrict data input by using a validation rule
Expressions for Numbers
Comparison
Sample
Expression
Description
Equal to
= 42
The value must be 42.
Less than
<100
The value must be less than 100.
Less than or equal to
Greater than
Greater than or equal
to
Not equal to
Greater than X and
less than Y
Between
<=100
>0
>= 0
<> 42
Not 42
>10 and <20
Between 0 and
100
>=0 and <=100
The value must be less than or equal to 100.
The value must be greater than 0.
The value must be greater than or equal to 0.
The value can be anything except 42.
The value must be greater than 10 and less
than 20. 10 and 20 are not included.
The value must be 0, 100, or somewhere in
between.
Expressions for Dates and Times
Comparison
Sample Expression
Description
Less than
<#30/1/2012#
The date occurs before January 30,
2012.
Greater than
>#30/1/2012#
The date occurs after January 30, 2012.
Between
Between
#1/10/2013# and
#31/10/2013#
The date occurs on October 2010.
Greater than the current
date
>Date( )
The date occurs today or after.
Less than the current date <Date( )
The date occurs yesterday or before.
Greater than the current
date (and time)
The date occurs today after the current
time, or any day in the future.
>Now()
Less than the current date
<Now()
(and time)
Page 1/6
The date occurs today before the current
time, or any day in the past.
Expressions for Dates and Times
Comparison
Sample Expression
Note: You have to write Full date.
Page 2/6
Description
Expressions for Text
With text, validation lets you verify that a value starts with, ends with, or contains
specific characters. You perform all these tasks with the Like operator, which compares
text to a pattern.
Sample Expression
Description
The asterisk (*) represents (zero or more) characters. Thus, the complete expression
asks Access to check that the value starts with R (or r), followed by a series of zero or
more characters.
starts with
ends with
Contains
Like "R*"
Like "*ed"
Like *5*
The text must start with the letter R.
The text must end with the letters ed.
requires that number 5 appears
somewhere in a text field
You can use the wildcard (?) to match a single character, which is handy
if you know how long text (field Size) should be or where a certain letter should
appear
eight-character product
code that ends with 0ZB
Five-character code that
begins with A.
Like "?????0ZB"
Like "A????"
Entry must be 8 characters and end with
the characters "0ZB".
Entry must be 5 characters and begin
with the letter "A".
OR
You can use the or keyword to accept a value if it meets one, two or more conditions.
>1000 Or <-1000
Like "A???????" or Like "B???????"
A or B or C or D or E
Amman or Aqaba
Null = EMPTY (Blank)
Page 3/6
If you must fill
Is Not Null
in the field
Page 4/6
Same as setting the field's Required property, but lets you
create a custom message (in the Validation Text property.)
To do this ...
Validation Rule
for Fields
Explanation
You must fill
in the field
Is Not Null
Same as setting the field's Required property, but
lets you create a custom message (in
the Validation Text property.)
Positive
numbers only
Is Null OR >= 0
Positive numbers only or empty
No more than
100%
Between -1 And 1
100% is 1. Use 0 instead of -1 if negative
percentages are not allowed.
Exactly 4 digits
Between 1000 And
9999
For Number fields.
No more than
100%
Between -1 And 1
100% is 1. Use 0 instead of -1 if negative
percentages are not allowed.
Not a future
date
<= Date()
Email address
Like "*?@?*.?*"
Limit to specific "M" Or "F"
choices
IN (1, 2, 4, 8)
Requires at least one character, @, at least one
character, dot, at least one character.
It is better to use a lookup table for the list, but
this may be useful for simple choices such as
Male/Female.
The IN operator may be simpler than several ORs.
ValidationText :
Use the ValidationText property to specify a message to be displayed to the user when
data is entered that violates a ValidationRule setting for a field.
Page 5/6
Input Mask
You can use the Input Mask property to make data entry easier and to control the values
users can enter in a field.
Character
Description
0
9
Digit (0 to 9, entry required, plus [+] and minus [] signs not allowed).
Digit or space (entry not required, plus and minus signs not allowed).
L
?
Letter (A to Z, entry required).
Letter (A to Z, entry optional).
A
a
Letter or digit (entry required).
Letter or digit (entry optional).
&
C
Any character or a space (entry required).
Any character or a space (entry optional).
<
>
Causes all characters to be converted to lowercase.
Causes all characters to be converted to uppercase.
Causes the character that follows to be displayed as the literal character (for
example, \A is displayed as just A).
To do this ...
Input Mask
Sample Values
10 digits
0000000000
4567654345
2 Letters followed by 3 digits
LL0000
AK2345
CD1234
1 Letter followed by Dash
then 2 digits
L\-00
A-23
A Phone Style
\(000") "000\-0000
(206) 555-0248
Password Field
Password
*******
Note:
You can Use the wizard button to set the Input Mask or Validation Rule.
Page 6/6