You are on page 1of 7

When you have several people entering data in your database, you can define how users must

enter data in specific fields to help maintain consistency and to make your database easier to manage. For example, you can set an input mask for a form so that users can only enter telephone numbers in the Swedish format or addresses in the French format. You can set a specific format for the input mask, and select another format so that the same data is displayed differently. This article will help you learn more about input masks, when to use them, and how to create them.

What do you want to do?


y y y y y
Learn more about input masks Know more about characters that define input masks Add or create input masks Consider the usage before applying an input mask Examples of input masks

Learn more about input masks


Let's start with where and when you might want to use input masks. You can add input masks to table fields, queries, and to form and report controls. For example, you can add an input mask to a Date/Time field in a table, or to a text box control on a form that you bind to a Date/Time field. You can also add input masks to form controls, such as text boxes, that you bind to table fields that are set to those data types. If you are unfamiliar with data types, see the article Introduction to data types and field properties. Input masks provide a set format for data entry in a field by using characters and symbols. When you apply an input mask to a field, anyone who inputs data in that field must follow the specific pattern defined by the input mask. For example, if the database user enters a phone number without the area code, in this particular mask, (___) 5550187 xt. ___ the user will be unable to save the data until the area code data is added. The exact behavior depends on the how the database designer sets up the input mask. Input masks provide a large amount of data validation and prevent users from entering invalid data (such as a phone number in a date field). Input masks can also help ensure that users enter data in a consistent way. That consistency can make data easier to find and make it easier to maintain your database. Remember that you define input masks to control the format in which data is entered in the database but you can apply another format to the same data to change how the data is displayed. For example, your input mask can define dates to be entered in a format such as YYYY.MM.DD, but have the date appear as DD-MMM-YYYY.

THE THREE PARTS OF AN INPUT MASK


Input masks are made up one mandatory part and two optional parts, and each part is separated by a semicolon. The purpose of each part is as follows: The first part is mandatory. It includes the mask characters or string (series of characters) along with placeholders and literal data such as, parentheses, periods, and hypens.

The second part is optional and refers to the embedded mask characters and how they are stored within the field. If the second part is set to 0, the characters are stored with the data, and if it is set to 1, the characters are only displayed and not stored. Setting the second part to 1 can save database storage space.

The third part of the input mask is also optional and indicates a single character or space that is used as a placeholder. By default, Access uses the underscore (_). If you want to use another character, enter it in the third part of your mask. For example, this is an input mask for a telephone numbers in the U.S. format:(999) 000-000;0;-: The mask uses two placeholder characters, 9 and 0. The 9 indicates an optional digit (which makes it optional to enter an area code), and each 0 indicates a mandatory digit.

y y y

The 0 in the second part of the input mask indicates that the mask characters will be stored along with the data. The third part of the input mask specifies that a hyphen (-) instead of the underscore (_) is to be used as the placeholder character.
TOP OF PAGE

Know more about characters that define input masks


The following table lists the placeholder and literal characters for an input mask and explains how it controls data entry:

CHARACTER EXPLANATION
0 9 # L ? A a & C .,:;-/ > < ! \ "" User must enter a digit (0 to 9). User can enter a digit (0 to 9). User can enter a digit, space, plus or minus sign. If skipped, Access enters a blank space. User must enter a letter. User can enter a letter. User must enter a letter or a digit. User can enter a letter or a digit. User must enter either a character or a space. User can enter characters or spaces. Decimal and thousands placeholders, date and time separators. The character you select depends on your Microsoft Windows regional settings. Coverts all characters that follow to uppercase. Converts all characters that follow to lowercase. Causes the input mask to fill from left to right instead of from right to left. Characters immediately following will be displayed literally. Characters enclosed in double quotation marks will be displayed literally.

TOP OF PAGE

Add or create input masks


You can either quickly add input masks by using the Input Mask Wizard, or specify masks manually by typing custom masks to the Input Mask field property setting.

ADD INPUT MASKS BY USING THE INPUT MASK WIZARD


This section describes how you can add a predefined input mask to a table field, a query, or a form or report control by using the Input Mask Wizard.

y y y

Add an input mask to a table field Add an input mask to a query Add an input mask to a form or report control

Add an input mask to a table field


You can use input masks with fields that are set to the Text, Number (except ReplicationID), Currency, and Date/Time data types.
NOTE

If you use an input mask for a Date/Time field, the Date Picker control becomes unavailable for that field.

1. 2. 3. 4. 5.

In the Navigation Pane, right-click the table and click Design View on the shortcut menu. Click the field where you want to add the input mask. Under Field Properties, on the General tab, click the Input Mask property box. Click the Build button to start the Input Mask Wizard.

In the Input Mask list, select the type of mask that you want to add.

6.

Click Try it and enter data to test how the mask displays.

7. 8. 9.

To keep the input mask without any changes, click Next. Select an option for how you want the data to be stored. Click Finish and save your changes. Top of section

Add an input mask to a query


1. 2. In the Navigation Pane, right-click the query that you want to change and click Design View on the shortcut menu. In the query design grid, place the pointer in the column for the field you want to change. You can place the cursor in any row for that field. 3. 4. 5. Press F4 to open the property sheet for the field. Under Field Properties, on the General tab, click the Input Mask property box. Click the Build button Top of section to start the Input Mask Wizard, and then follow the instructions in the wizard.

Add an input mask to a form or report control


1. In the Navigation Pane, right-click the form or report that you want to change and click Design View on the shortcut menu. 2. 3. 4. Right-click the control that you want to change, and then click Properties on the shortcut menu. On the All tab, click the Input Mask property box. Click theBuild button Top of section to start the Input Mask Wizard, and then follow the instructions in the wizard.

CREATE CUSTOM INPUT MASKS


While the Input Mask Wizard provides input masks for most common formatting needs, you may sometimes want to customize input masks to better suit your needs. Input masks can be customized by either changing the predefined masks from the Input Mask Wizard or by manually changing the Input Mask property for a field where you want the mask applied.

Customizing input masks from the Input Mask Wizard


1. 2. 3. Open the object in Design View, and click the field where you want to add the custom input mask. Click the Build Click Edit List. The Customize Input Mask Wizard dialog box appears. 4. 5. Enter a new description in the Description text box using characters and placeholders from the table. Click the Mask Type down arrow and select a suitable mask type. to start the Input Mask Wizard.

6.

Click Close. The new input mask displays in the list.

Customize input masks from the field property setting


1. 2. 3. 4. In the Navigation Pane, right-click the object and click Design View on the shortcut menu. Click the field where you want to create the custom input mask. In the Field Properties area, click the Input Mask text box, and then type your custom mask. Press CTRL+S to save your changes. For more information about how to define an input mask, click the Input Maskproperty box, and then press F1. You must manually type the input mask definition for Number and Currency fields.
TOP OF PAGE

Consider the usage before applying an input mask


It is usually a good idea to consider how data entry needs might change as your database grows and here are several general questions that you can start with: Will the mask prevent users from entering necessary data? For example, will users ever need to enter phone in a format from another region?

y y

Does the mask interfere with the display format settings? For example, switch to Design view and, in the Format property of the field that contains your input mask, type this format string: (&&&) @@@-@@@@. When you view the field in Datasheet view, you see something like this: (425() 5) 55--1212.

Do you plan on using the Date Picker on a Date/Time field? If you do, then you cannot apply an input mask to that field.
TOP OF PAGE

Examples of input masks


The examples in the following table demonstrate some ways that you can use input masks.

THIS INPUT MASK


(000) 000-0000

PROVIDES THIS TYPE OF VALUE


(206) 555-0199

NOTES
In this case, you must must enter an area code because that section of the mask (000, enclosed in parentheses) uses the 0 placeholder. In this case, the area code section uses the 9 placeholder, so area codes are optional. Also, the exclamation point (!) causes the mask to fill in from left to right. Allows you to substitute the last four digits of a U.S. style phone number with letters. Note the use of the 0 placeholder in the area code section, which makes the area code mandatory.

(999) 000-0000!

(206) 555-0199 ( ) 555-0199

(000) AAA-AAAA

(206) 555-TELE

#999

-20 2000 GREENGR339M3 MAY R 452B7

Any positive or negative number, no more than four characters, and with no thousands separator or decimal places. A combination of mandatory (L) and optional (?) letters and mandatory numbers (0). The greaterthan sign forces users to enter all letters in uppercase. To use an input mask of this type, you must set the data type for the table field to Text or Memo. A mandatory postal code and an optional plusfour section. A first or last name with the first letter automatically capitalized. A book number with the literal text, mandatory first and last digits, and any combination of letters and characters between those digits. A combination of mandatory letters and characters, all uppercase. Use this type of input mask, for example, to help users enter part numbers or other forms of inventory correctly.

>L????L?000L0

00000-9999 >L<?????????????? ISBN 0&&&&&&&&&-0 >LL00000-0000

9811598115-3007 Maria Pierre ISBN 1-55615-507-7

DB51392-0493

Microsoft Access interprets characters in the InputMaskproperty definition as shown in the following table. To define a literal character, enter any character other than those shown in the table, including spaces and symbols. To define one of the following characters as a literal character, precede that character with a backslash (\).

CHARACTER DESCRIPTION
0 9 # L ? A a & C .,:;-/ Digit (0 through 9, entry required; plus [+] and minus [-] signs not allowed). Digit or space (entry not required; plus and minus signs not allowed). Digit or space (entry not required; blank positions converted to spaces, plus and minus signs allowed). Letter (A through Z, entry required). Letter (A through Z, entry optional). Letter or digit (entry required). Letter or digit (entry optional). Any character or a space (entry required). Any character or a space (entry optional). Decimal placeholder and thousands, date, and time separators. (The actual character used depends on the regional settings specified in Microsoft Windows Control Panel.) Causes all characters that follow to be converted to lowercase. Causes all characters that follow to be converted to uppercase. Causes the input mask to display from right to left, rather than from left to

< > !

right. Characters typed into the mask always fill it from left to right. You can include the exclamation point anywhere in the input mask. \ Causes the character that follows to be displayed as a literal character. Used to display any of the characters listed in this table as literal characters (for example, \A is displayed as just A). Setting the InputMask property to the word Password creates a password entry text box. Any character typed in the text box is stored as the character but is displayed as an asterisk (*).

Password

Input mask examples The following table shows some useful input mask definitions and examples of values you can enter into them.

INPUT MASK DEFINITION EXAMPLES OF VALUES


(000) 000-0000 (999) 999-9999! (000) AAA-AAAA #999 >L????L?000L0 >L0L 0L0 00000-9999 >L<?????????????? ISBN 0-&&&&&&&&&-0 >LL00000-0000 (206) 555-0248 (206) 555-0248 ( ) 555-0248 (206) 555-TELE -20 2000 GREENGR339M3 MAY R 452B7 T2F 8M4 9811598115-3007 Maria Pierre ISBN 1-55615-507-7 ISBN 0-13-964262-5 DB51392-0493

You might also like