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: 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. Entering text such as "Enter values between and 1," 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.
For example, an input mask can force users to enter dates in a European format, such as 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.
Types of validation rules You can create two basic types of validation rules: Your rule now requires users to enter dates on or after January 1, If you enter a date earlier than and then try to place the focus on another field, Access prevents you from leaving the current field until you fix the problem. 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. 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. Where you can use validation rules You can define validation rules for table fields and for controls on forms.
When you define rules for tables, those rules apply when you import data. To add validation rules to a table, you open the table and use commands on the Fields tab of the ribbon.
To add validation rules to a form, you open the form in Layout view and add rules to the properties of individual controls. 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. You can use an expression to perform calculations, manipulate characters, or test data.
A validation rule expression tests data. Expressions can also perform mathematical operations. The expression [OrderDate] - [ShipDate] calculates the number of days that elapsed between the time an order was placed and the time it shipped. For more information about expressions, see the article Build an expression. A field validation rule checks input to a field, and is applied when the focus leaves the field. A record validation rule checks input to one or more fields is applied when the focus leaves the record.
Usually, a record validation rule compares the values of two or more fields. The following field types do not support validation rules: