MS-Access / Getting Started

Defining Input Masks

To assist you in entering formatted data, Access 2010 allows you to define an input mask for Text, Number (except Replication ID), Date/Time, and Currency data types. You can use an input mask to do something as simple as forcing all letters entered to be uppercase or as complex as adding parentheses and hyphens to phone numbers. You create an input mask by using the special mask definition characters shown in Table-6. You can also embed strings of characters that you want to display for formatting or store in the data field.

Table-6 Input Mask Definition Characters
Mask CharacterMeaning
0A single digit must be entered in this position.
9A digit or a space can be entered in this position. If the user skips this position by moving the insertion point past the position without entering anything, Access stores nothing in this position.
#A digit, a space, or a plus or minus sign can be entered in this position. If the user skips this position by moving the insertion point past the position without entering anything, Access stores a space.
LA letter must be entered in this position.
?A letter can be entered in this position. If the user skips this position by moving the insertion point past the position without entering anything, Access stores nothing.
AA letter or a digit must be entered in this position.
aA letter or a digit can be entered in this position. If the user skips this position by moving the insertion point past the position without entering anything, Access stores nothing.
&A character or a space must be entered in this position.
CAny character or a space can be entered in this position. If the user skips this position by moving the insertion point past the position without entering anything, Access stores nothing.
.Decimal placeholder (depends on the setting in the Regional And Language Options item in Control Panel).
,Thousands separator (depends on the setting in the Regional And Language Options item in Control Panel).
: ; - /Date and time separators (depends on the settings in the Regional And Language Options item in Control Panel).
<Converts to lowercase all characters that follow.
>Converts to uppercase all characters that follow.
!Causes the mask to fill from right to left when you define optional characters on the left end of the mask. You can place this character anywhere in the mask.
\Causes the character immediately following to be displayed as a literal character rather than as a mask character.
"literal"You can also enclose any literal string in double quotation marks rather than use the \ character repeatedly.

An input mask consists of three parts, separated by semicolons. The first part defines the mask string using mask definition characters and embedded literal data. The optional second part indicates whether you want the embedded literal characters stored in the field in the database. Set this second part to 0 to store the characters or to 1 to store only the data entered. The optional third part defines a single character that Access 2010 uses as a placeholder to indicate positions where data can be entered. The default placeholder character is an underscore (_).

Perhaps the best way to learn to use input masks is to take advantage of the Input Mask Wizard. In the Companies table of the Contact Tracking database, the PhoneNumber field could benefit from the use of an input mask. Click the PhoneNumber field in the upper part of the Table window in Design view, and then click in the Input Mask property box in the lower part of the window. You should see a small button with three dots on it (called the Build button) to the right of the property box.

Click the Build button to start the Input Mask Wizard. If you haven't already saved the table, the wizard will insist that you do so. Save the table and name it Companies. When Access 2010 warns you that you have not defined a primary key and asks if you want to create a primary key now, click No. We'll define a primary key in the next section. On the first page, the wizard gives you a number of choices for standard input masks that it can generate for you. In this case, click the first one in the list-Phone Number. Note that you can type something in the Try It box below the Input Mask list to test the mask.

Click Next to go to the next page. On this page, you can see the mask name, the proposed mask string, a list from which you select the placeholder character, and another Try It box. The default underscore character (_) works well as a placeholder character for phone numbers.

Click Next to go to the next page, where you can choose whether you want the data stored without the formatting characters (the default) or stored with the parentheses, spaces, and hyphen separator.

Remember Although an input mask can be very useful to help guide the user to enter valid data, if you define an input mask incorrectly or do not consider all possible valid values, you can prevent the user from entering necessary data.

[Previous] [Contents] [Next]