About restricting or validating data

Microsoft Access provides a variety of ways to control how users enter data into your database. For example, you can limit the data that a user can enter into a field by defining a validation rule for that field. If the data that a user enters into the field breaks the rule, Access will display a message telling the user what kind of entries are allowed. Another method of controlling data entry is to create an input mask to restrict the kind of values that can be entered in positions across the field. You can perform these simple forms of validation and restriction by setting properties for fields in tables, or by setting properties for controls on forms.

In most cases, it is preferable to define data validation and restriction by setting a field's properties in table Design view. That way, whenever you use that field in a form, the field's validation rule and other properties will apply to data entry performed using the form.

However, if the data entered into a control on a form isn't bound to a field in a table, and you need to restrict or validate data entry, you must define those properties in the form. Additionally, there are situations where you must use macros or Microsoft Visual Basic for Applications code in conjunction with a form to perform more complex validation. For example, you might want to be able to override your validation rule or compare values from different tables.

Using data types and field properties to restrict or validate data in tables

Microsoft Access provides a variety of ways to control how data is entered in fields in your table.

The first thing you should consider is whether a field has an appropriate data type. For example, Date/Time fields only allow entry of valid date and time formats. If you are currently using a Text field for such information, it may be appropriate to change the field to a Date/Time field.

You can set field properties that provide further control over the values that can be entered into the field:

Validation rules

Validation rules allow you to define a rule to limit what will be accepted. They are enforced whenever you add or edit data, whether it is through table Datasheet view, a form bound to the table, an append query, an update query, Visual Basic for Applications code, or by importing data from another table. You can define two kinds of validation rules: field validation rules and record validation rules.

When a field or record validation rule is broken, Access displays a message that informs the user how to properly enter data.

Using a macro or event procedure for data validation

In most cases, you can verify that data is entered correctly into a control on a form by setting the ValidationRule property for the control, or by setting record or field validation rules in the underlying table to which the control is bound. Macros and event procedures provide additional power and flexibility for more complex validation.

Use a macro or an event procedure for data validation if: