Restrict data input by using validation rules - Microsoft Support
Restrict data input by using validation rules - Microsoft Support
You can vet or validate data in Access desktop databases as you enter it by using validation rules. You can Unlock now
use the expression builder to help you format the rule correctly. Validation rules can be set in either table
design or table datasheet view. There are three types of validation rules in Access:
1. Field Validation Rule You can use a field validation rule to specify a criterion that all valid field values
must meet. You should not have to specify the current field as a part of the rule unless you are using the
field in a function. Restrictions on types of characters to be entered in a field may be easier to do with an
Input Mask. For example, a date field might have a validation rule that disallows values in the past.
Quick examples:
2. Record Validation Rule You can use a record validation rule to specify a condition that all valid records
must satisfy. You can compare values across different fields using a record validation rule. For example, a
record with two date fields might require that values of one field always precede values of the other field
(e.g., StartDate is before EndDate).
Quick examples:
3. Validation on a form You can use the Validation Rule property of a control on a form to specify a
criterion that all values input to that control must meet. The Validation Rule control property works like a
field validation rule. Typically, you use a form validation rule instead of a field validation rule if the rule was
specific only to that form and not to the table no matter where it was used.
In this article
Overview
Overview
This article explains how to use validation rules and validation text in table fields and form controls. A
validation rule is one way to restrict input in a table field or a control (such as a text box) on a form.
Validation text lets you provide a message to help users who input data that is not valid.
When data is entered, Access checks to see whether the input breaks a validation rule – if so, the input is not
accepted, and Access displays a message.
Data types Every table field has a data type that restricts what users can enter. For example, a
Date/Time field accepts only dates and times, a Currency field accepts only monetary data, and so
on.
Field properties Some field properties restrict data input. For example, the Field Size property of
a field restricts input by limiting the amount of data.
You can also use the Validation Rule property to require specific values, and the Validation Text
property to alert your users to any mistakes. For example, entering a rule such as >100 And <1000
in the Validation Rule property forces users to enter values between 100 and 1,000. A rule such as
[EndDate]>=[StartDate] forces users to enter an ending date that occurs on or after a starting
date. Entering text such as "Enter values between 100 and 1,000" or "Enter an ending date on or after
the start date" in the Validation Text property tells users when they have made a mistake and how
to fix the error.
Input masks You can use an input mask to validate data by forcing users to enter values in a
specific way. For example, an input mask can force users to enter dates in a European format, such as
2007.04.14.
You can use these methods of validating data alone or in combination with each other. Data types are not
optional, and provide the most basic type of data validation.
For more information about data types, field sizes, and input masks, see the article Introduction to data types
and field properties.
Field validation rules Use a field validation rule to check the value that you enter in a field when
you leave the field. For example, suppose you have a Date field, and you enter >=#01/01/2010# in
the Validation Rule property of that field. Your rule now requires users to enter dates on or after
January 1, 2010. If you enter a date earlier than 2010 and then try to place the focus on another field,
Access prevents you from leaving the current field until you fix the problem.
Record validation rules Use a record validation rule to control when you can save a record (a row
in a table). Unlike a field validation rule, a record validation rule refers to other fields in the same
table. You create record validation rules when you need to check the values in one field against the
values in another. For example, suppose your business requires you to ship products within 30 days
and, if you don't ship within that time, you must refund part of the purchase price to your customer.
You can define a record validation rule such as [RequiredDate]<=[OrderDate]+30 to ensure that
someone doesn't enter a ship date (the value in the RequiredDate field) too far into the future.
If the syntax for validation rules looks cryptic, see the section What you can put in a validation rule for an
explanation of the syntax and some example validation rules.
The steps in the section Add a validation rule to a table explain how to add validation rules to table fields.
The steps in the section Add a validation rule to a control on a form, later in this article, explain how to add
rules to the properties in individual controls.
For more information about expressions, see the article Build an expression.
Top of Page
Notes:
Notes: The following field types do not support validation rules:
AutoNumber
OLE Object
Attachment
ReplicationID
2. On the Table Fields tab, in the Field Validation group, click Validation
Validation, and then click Field
Validation Rule
Rule.
3. Use the Expression Builder to create the rule. For more information about using the Expression
Builder, see the article Use the Expression Builder.
1. Select the field that needs a message for input that is not valid. The field should already have a
validation rule.
2. On the Table Fields tab, in the Field Validation group, click Validation
Validation, and then click Field
Validation Message
Message.
For some examples of field validation rules and messages, see the section Validation rule reference.
2. On the Table Fields tab, in the Field Validation group, click Validation
Validation, and then click
Validation Rule
Rule.
3. Use the Expression Builder to create the rule. For more information about using the Expression
Builder, see the article Use the Expression Builder.
1. Open the table that needs a message for input that is not valid. The table should already have a
record validation rule.
2. On the Table Fields tab, in the Field Validation group, click Validation
Validation, and then click
Validation Message
Message.
Top of Page
On the Table Design tab, in the Tools group, click Test Validation Rules
Rules.
2. Click Yes to close the alert message and start the test.
4. You might see a variety of other alert messages as you proceed. Read the instructions in each
message, and then click Yes or No
No, as appropriate, to complete or stop the testing.
Top of Page
Tip:
Tip: If you create a form automatically from a table by using one of the Form commands on the ribbon, any
validation for fields in the underlying table are inherited by the corresponding controls on the form.
A control can have a different validation rule from the table field to which the control is bound. This is useful
if you want the form to be more restrictive than the table. The form rule is applied, and then the table rule is
applied. If the table is more restrictive than the form, the rule defined for the table field takes precedence. If
the rules are mutually exclusive, they prevent you from entering any data at all.
For example, suppose you apply the following rule to a date field in a table:
<#01/01/2010#
But you then apply this rule to the form control that is bound to the date field:
>=#01/01/2010#
The date field now requires values earlier than the year 2010, but the form control requires dates have that
year or later, thus preventing you from entering any data at all.
1. Right-click the form that you want to change, and then click Layout View
View.
2. Right-click the control that you want to change, and then click Properties to open the property
sheet for the control.
3. Click the All tab, and then enter your validation rule in the Validation Rule property box.
Tip:
Tip: Click the Build
Build button to start the Expression Builder.
For more information about using the Expression Builder, see the article Use the Expression Builder.
Top of Page
-or-
BETWEEN 0 AND 1 Enter a value with a percent sign. (For use with a field that
stores number values as percentages).
LIKE "[A-Z]*@[A-Z].com" OR "[A-Z]*@[A- Enter a valid .com, .net, or .org e-mail address.
Z].net" OR "[A-Z]*@[A-Z].org"
NOT Tests for converse values. Use before any comparison NOT > 10 (the same as
operator except IS NOT NULL. <=10
<=10).
IN
N Tests for values equal to existing members in a list. IN
Comparison value must be a comma-separated list ("Tokyo","Paris","Moscow")
enclosed in parentheses.
BETWEEN Tests for a range of values. You must use two comparison BETWEEN 100 AND 1000
values — low and high — and you must separate those (the same as >=100 AND
values with the AND separator. <=1000
<=1000)
LIKE Matches pattern strings in Text and Memo fields. LIKE "Geo*"
IS
IS NOT
NOT Forces users to enter values in the field. This is the same as IS
IS NOT
NOT NULL
NULL
NULL
NULL setting the Required
Required field property to YesYes. However,
when you enable the Required
Required property and a user fails
to enter a value, Access displays a somewhat unfriendly
error message. Typically, your database is easier to use if
you use IS NOT NULL and enter a friendly message in the
Validation
Validation Text
Text property.
AND
AND Specifies that all parts of the validation rule must be true. >=
>= #01/01/2007#
#01/01/2007# AND
AND
<=#03/06/2008#
<=#03/06/2008#
Note:
Note: You can also use AND
AND to
combine validation rules. For
example: NOT
NOT "UK"
"UK" AND
AND LIKE
LIKE
"U*"
"U*".
OR
OR Specifies that some but not all parts of the validation rule January
January OR
OR February
February
must be true.
<
< Less than.
<=
<= Less than or equal to.
>
> Greater than.
>=
>= Greater than or equal to.
=
= Equal to.
<>
<> Not equal to.
By default, all .accdb and .mdb files use the ANSI-89 standard.
You can change the ANSI standard for a database to ANSI-92 by using the following procedure:
1. On the File
File tab, click Options
Options.
2. In the Access
Access Options
Options dialog box, click Object
Object Designers
Designers.
3. In the Query
Query design
design section, under SQL
SQL Server
Server Compatible
Compatible Syntax
Syntax (ANSI-92)
(ANSI-92), select This
This
database
database.
For more information about using wildcard characters and the ANSI standards for SQL, see the article Access
wildcard character reference.
Top of Page
Discover Community
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
What's
What's new
new Microsoft
Microsoft Store
Store Education
Education Business
Business Developer
Developer &
& IT
IT Company
Company
Surface Pro Account profile Microsoft in education Microsoft Cloud Azure Careers
Surface Laptop Download Center Devices for education Microsoft Security Microsoft Developer About Microsoft
Surface Laptop Studio 2 Microsoft Store support Microsoft Teams for Education Dynamics 365 Microsoft Learn Company news
Surface Laptop Go 3 Returns Microsoft 365 Education Microsoft 365 Explore ISV Success Privacy at Microsoft
Microsoft Copilot Order tracking How to buy for your school Microsoft Power Platform Microsoft Tech Community Investors
AI in Windows Certified Refurbished Educator training and Microsoft Teams Azure Marketplace Diversity and inclusion
development
Explore Microsoft products Microsoft Store Promise Microsoft 365 Copilot AppSource Accessibility
Deals for students and parents
Windows 11 apps Flexible Payments Small Business Visual Studio Sustainability
Azure for students