Microsoft Office Tutorials and References
In Depth Information
Using Input Masks to Validate and Format Data
✦ They block any data that doesn’t fit the mold from being entered. You
can’t enter 12 characters if the input mask specifies 4, and you can’t
enter a digit followed by 3 letters if the input mask specifies 2 letters
followed by 2 digits.
Use input masks when you know the form the data should take, such as a
ten-digit phone number, a nine-digit zip code, or an item number that must
be two letters followed by three or more digits.
A manually entered input mask is even more flexible because you can, say,
require two digits and then allow a third, and the same is true with letters.
See “Creating an input mask manually,” later in this chapter, for more details
on defining a custom input mask.
Using the input mask, you can add formatting characters, such as adding
parentheses and a hyphen to phone numbers. You can also change the way a
value appears, such as choosing to display a date as 27-sep-06 or 9/27/06
or displaying hyphens in a Social Security number. The input mask for the
field is in effect when you enter data in the field from a datasheet or a form.
If the data in a field varies or isn’t easily described, the field probably isn’t
a good candidate for an input mask. Street addresses, for example, come
in too many formats to describe easily, so making an input mask for an
Address field is difficult and could prevent valid entries (and frustrate the
person entering data). You can create input masks for Short Text, Number,
Date/Time, and Currency field types; other data types don’t have the Input
Mask field property.
You can use an input mask with a validation rule to protect a field from data
that’s incorrect or that just doesn’t belong there. Validation rules give you
more flexibility in limiting the data you can enter, and we discuss them
further later in this chapter.
Input masks are commonly defined in Design view, where they become part
of the field definition, and they also apply in forms. You can add input masks
to queries and forms in which data may be entered, and the input mask is
defined only for that object. In all cases, you have to add an input mask from
Using the Input Mask Wizard
The easiest way to create an input mask is to use the Input Mask Wizard. The
wizard can help you create the input mask for your data, especially if the data
in the field is a common type, such as a phone number or a zip code.
If your data is similar to one of the data types in the Input Mask Wizard, you
may want to use the wizard and then edit the input mask in Design view.