Académique Documents
Professionnel Documents
Culture Documents
You can vet or validate data as it is input to help improve accuracy and consistency, by using validation rules. There are three ways to use validation rules:
Field Validation Rule You can use a validation rule to specify a criterion that all valid field values must meet. For example, a date field might have a validation rule that disallows values in the past. Record Validation Rule You can use a validation rule to specify a condition that all valid records must satisfy. 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). 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.
In this article
Overview Add a validation rule to a table Test existing data against a new validation rule Add a validation rule to a control on a form Validation rule reference
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. Access provides a number of ways to restrict input:
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.
2. On the Fields tab, in the Field Validation group, click Validation, and then click Field Validation 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.
2. Click Yes to close the alert message and start the test. 3. If prompted to save your table, Click Yes. 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, as appropriate, to complete or stop the testing. Top of Page
Tip
For more information about using the Expression Builder, see the article Use the Expression Builder.
>=0
0 or >100 BETWEEN 0 AND 1 <#01/01/2007# >=#01/01/2007# AND <#01/01/2008# <Date() StrComp(UCase([LastName]), [LastName],0) = 0 >=Int(Now()) M Or F LIKE "[A-Z]*@[A-Z].com" OR "[A-Z]*@[AZ].net" OR "[A-Z]*@[A-Z].org" [RequiredDate]<=[OrderDate]+30 [EndDate]>=[StartDate]
Tests for values equal to existing members in a list. Comparison value must be a IN comma-separated list enclosed in parentheses. Tests for a range of values. You must use two comparison values low and high BETWEEN and you must separate those values with the AND separator. Matches pattern strings in Text and Memo LIKE fields. Forces users to enter values in the field. This is the same as setting the Required field property to Yes. However, when you enable the Required property and a user fails to enter a value, Access displays a IS NOT somewhat unfriendly error message. NULL Typically, your database is easier to use if you use IS NOT NULL and enter a friendly message in the Validation Text property.
IN ("Tokyo","Paris","Moscow")
BETWEEN 100 AND 1000 (the same as >=100 AND <=1000) LIKE "Geo*"
IS NOT NULL
>= #01/01/2007# AND <=#03/06/2008# AND Specifies that all parts of the validation rule must be true. Note You can also use AND to combine validation rules. For example: NOT "UK" AND LIKE "U*".
Specifies that some but not all parts of the January OR February validation rule must be true. Less than. Less than or equal to. Greater than. Greater than or equal to. Equal to. Not equal to.
reside on a computer running Microsoft SQL Server, and the forms, reports and other objects reside on other computers. You can change the ANSI standard for a database to ANSI-92 by using the following procedure: 1. On the File tab, click Options. 2. In the Access Options dialog box, click Object Designers. 3. In the Query design section, under SQL Server Compatible Syntax (ANSI-92), select This database. For more information about using wildcard characters and the ANSI standards for SQL, see the article Access wildcard character reference.