Access 2013
Modifying Tables
Field character limits
Setting the character limit for a field sets a rule about how many characters—letters, numbers, punctuation, and even spaces—can be entered in that field. This can help to keep the data in your records concise, or even to force the user to enter the data a certain way.
In the example below, a user is entering records that include addresses. If you set the character limit in the State field as 2, the user can only enter two characters of information. This means the user must enter postal abbreviations for the states instead of the full name—here, NC instead of North Carolina. Note that you can only set a character limit for fields defined as text.
To set a character limit for a field:
- Select the desired field.
- Click the Fields tab, then locate the Properties group.
- In the Field Size box, type the maximum number of characters you would like to allow in your field.
Setting a 2-character limit on the State field
- Save your table. The character limit for the field will be set.
Validation rules
A validation rule is a rule that dictates which information can be entered into a field. When a validation rule is in place, it is impossible for a user to enter data that violates that rule. For example, if we were asking the user to input a state name into a table with contact information, we might create a rule that limits the valid responses to US state postal codes. This would prevent users from typing something that wasn't actually a real state postal code.
In the example below, we will apply that rule to our Customers table. It's a fairly simple validation rule—we'll just name all of the valid responses a user could enter, which will mean the user can't type anything else into the record. However, it's possible to create validation rules that are much more complex. For detailed information on how to write validation rules, review this tutorial from Microsoft on creating validation rules.
To create a validation rule:
- Select the field you wish to add a validation rule to. In our example, we'll set a rule for the State field.
- Select the Fields tab, then locate the Field Validation group. Click the Validation drop-down command, then select Field Validation Rule.
Clicking the Field Validation Rule command
- The Expression Builder dialog box will appear. Click the text box, and type in your validation rule. In our example, we want to limit data in the State field to actual state postal codes. We'll type each of the valid responses in quotation marks and separate them with the word Or, which lets Access know that this field can accept the response "AL" or "AK" or "AZ" or any of the other terms we've entered.
Typing our validation rule, which will contain every state postal code, each separated by the word "Or"
- Once you're satisfied with the validation rule, click OK. The dialog box will close.
- Click the Validation drop-down command again. This time, select Field Validation Message.
Clicking the Field Validation Message command
- A dialog box will appear. Type the phrase you would like to appear in an error message when a user tries to enter data that violates the validation rule. Your message should let the user know what data is permitted.
Typing the phrase that will appear as an error message
- When you're satisfied with the error message, click OK.
- The validation rule is now included in the field. Users will be unable to enter data that violates the rule.
Data has been entered that violates the validation rule
Simple validation rules can be written exactly like query criteria. The only difference is that query criteria search for data, while an identical validation rule either permits or rejects data. To see examples of query criteria, review our Query Criteria Quick Reference Guide.