Share this Page URL

Managing the Consistency, Format, and Integrity of Your Data 99 Validating Data Tables and fields (except fields with the AutoNumber or OLE Object data type) have a property named Validation Rule. Validation rules describe a set of values a field can contain or a set of conditions that must be met before a record can be saved in a table. A field validation rule checks whether the data entered in a field is valid when the focus leaves that field (when you press Enter or Tab, or when you click outside the field). A validation rule for a field named Color might be an expression such as the following: "Green" Or "Red" Or "Black" Entering White in the field would cause an error when you move the focus from that field. A validation rule applied to an entire table (also known as a record validation rule) determines whether the values in a record are valid. A table validation rule often compares values in different fields. For example, a table validation rule might require that the value in the ShipDate field be earlier than the date in the OrderDue field. Access would not let you save a record with an order due date that's before the ship date. When data violates a validation rule, Access displays a message. You can replace the standard Access message by using the Validation Text property to craft a message of your own. For example, for the sample field validation rule shown above, you could enter the message "This item is available only in green, red, or black" in the Validation Text property. In the next set of steps, we'll enter a validation rule for the MarketingCampaigns table using the Expression Builder. We'll also look at a situation in which using a field validation rule is possible but might lessen flexibility you need in your database. Here are the steps to follow. Enter a validation rule