Lesson 5 | Use an input mask to limit data |
Objective | Use the Input Mask Wizard. |
Use Input mask to limit Data
It is certainly not obvious from the name what an input mask is used for. An input
mask defines a pattern for the data that can be entered in a specific field and prevents data that doesnt match that pattern from being entered in the field. For instance, if you have a product number that is two letters followed by four digits, an input mask can ensure that data that does not match that pattern is blocked from being entered. Input masks allow a little bit of flexibility, but in order to be useful you have to have a good idea of what correct input into the field should look like. The easiest way to use an input mask is to let the Input Mask Wizard do the work for you. This simulation shows you how to use the Input Mask Wizard.
Using the Input Mask Wizard
- This table contains employee names and a field for social security numbers. By using the input mask, you will require that all social security numbers be nine digits. They will also appear with hyphens in the right places, even though the user enters only the nine digits. Input masks are defined from the table Design view, so click the View button to see this table in Design view.
- Heres the table in Design view. The SSN field is the active field (you can tell because of the triangle in front of the field name) so the field properties at the bottom of the window are those for SSN. The first step in creating an input mask is to click in the Input Mask
field (on the General tab in the field properties).
- When you make the Input Mask setting active, a button appears to the right of the setting. This button is called the Build button, and it
launches the Input Mask Wizard. Click the Input Mask Build button.
- The Input Mask Wizard provides a number of common patterns for the type of data the input mask will allow. Social Security Number, the second choice, is the option you are going to choose. Click Social Security Number to select it as the pattern for your input mask. Next, click the Try It box to see how the input mask will look when you enter data into the field.
- The Try It box displays an underscore for each character (in this case all numbers) to be input. The social security number input mask also adds two dashes. That means that although you only type the nine digits, the number appears with two dashes: one after the first three digits and one before the last four digits (where you are accustomed to seeing them).
Click again in the Try it box and we will type the following social security number for you: 123456789. Now click the Next button to go to the next window of the wizard.
- This window of the Input Mask Wizard enables you to customize the input mask. The first setting allows you to change the way the mask works. Here you see nine zeros and two hyphens--the zeros mean that a number must be entered, and the hyphens are automatically put in the right places. You will learn more about the symbols used in input masks later. The placeholder character is usually an underscore as shown here, but you can choose from a list of placeholders. The settings on this page are fine for your input mask, so click the Next button to see the next window.
- This window also enables you to adjust the input mask. Here you can decide whether you want to save the extra characters (in this case, the hyphens) that the input mask adds to the display, or just save the characters that are typed and only use the additional characters for display purposes. Click the Next button to see the last window of the wizard.
- Here is the last window of the wizard, simply click the Finish button to create the input mask.
- You now see the input mask in the field properties that the Input Mask Wizard created for you. The input mask has three parts separated by semicolons: the first part defines the allowable input, the second part (which is blank) tells Access not to store the extra characters (the hyphens), and the third part shows the placeholder characters that the user will see. Now click the View button to see the table in Datasheet view. Because you have made a change to the table design (you have added an input mask), Access tells you that you have to save the table before you can view it in Datasheet view. Click the Yes button to save the table.
- This is what the users see when they enter data--they must enter nine digits and the hyphens help to make the display clearer.
It is also possible to define your own input mask.
Creating Access input mask from scratch
As you saw in the simulation, what the Input Mask Wizard does is enter a series of characters in the Input Mask setting.
If your data is not described by any of the patterns found in the Input Mask Wizard, you might want to create your own input mask from scratch.
Often it is easier to edit an input mask
created by the wizard than to create one from scratch--pick a pattern that is similar to the pattern of your data.
The input mask consists of three parts separated by semicolons: the data pattern, a zero to store any additional characters added to the display or a 1 (or blank) not to store them, and the placeholder characters that the user will see. The most important part of the input mask is defining the data pattern. The characters shown in the following table are used to define the data pattern.
Learn how to select fields in Datasheet and Design views.