|
Chapter 6: Keeping Your Information Accurate continued
Using an Input Mask to Restrict DataWhen you use masks in tables or forms, people entering information can see at a glance the format in which they should make entries and how long they should be. You can use the InputMask property to control how data is entered in text, number, date/time, and currency fields. This property has three sections, separated by semi-colons, like the mask for a telephone number shown here:!\(000") "000\-0000;1;# The first section contains characters that are used as placeholders for the information to be typed, as well as characters such as parentheses and hyphens. Together, all these characters control the appearance of the entry. The following list explains the purpose of the most common input mask characters:
Any characters not included on this list are displayed as literal characters. If you want to use one of the special characters in this list as a literal character, precede it with the \ character. The second and third sections of the input mask are optional. Including a 1 or leaving nothing in the second section tells Access to store only the characters entered; including a 0 tells it to store both the characters entered and the mask characters. The character in the third section is displayed in a new record as the placeholder for the characters to be typed. This placeholder defaults to an underscore if the section is omitted. The input mask !\(000") "000\-0000;1;# creates this display in a field in both a table and a form: (###) ###-#### In this case, you are restricting the entry to ten digitsno more and no less. Access stores just the digits entered, not the parentheses, space, and dash (though those characters could be displayed in your table, form, or report if you set the correct format property). In this exercise, you will use the Input Mask Wizard to apply a predefined telephone input mask to a text field, forcing entered numbers into the (206) 555-0001 format. You will then create a custom mask to force the first letter of an entry to be upper-case (a capital letter). The working folder for this exercise is SBS\Access\Accurate\InputMask. Follow these steps:
You can create an input mask by hand for text, number, date, or currency fields, or you can use this wizard to apply one of several standard masks for text and date fields.
The second page of the wizard displays the input mask and gives you the opportunity to change the placeholder character that will indicate what to type. The exclamation point causes Access to fill the mask from left to right with whatever is typed. The parentheses and hyphen are characters that Access will insert in the specified places. The 9s represent optional digits, and the 0s represent required digits, so you can enter a telephone number with or without an area code.
TIP: Because Access fills the mask from left to right, you would have to press the Right Arrow key to move the insertion point past the first three placeholders to enter a telephone number without an area code.
The dialog box now looks like this:
On the third page of the wizard, you specify whether you want to store the symbols with the data. If you store them, the data will always be displayed in tables, forms, and reports in this format. However, the symbols take up space, meaning that your database will be larger.
Access closes the wizard and displays the edited mask as the Input Mask property, as shown on the next page.
Access changes the format of the mask to !\(000") "000\- 0000;;#. Notice the two semicolons that separate the mask into its three sections. Since you told Access to store data without the symbols, nothing is displayed in the second section of the mask.
Any letters you type are ignored. The first ten digits are formatted as a telephone number. If you type more than ten digits, they are also ignored. If you type fewer than ten digits and press Tab or Enter, Access warns you that your entry doesn’t match the input mask.
TIP: An input mask can contain more than just the placeholders for the data to be entered. If, for example, you type The number is in front of the telephone number in the Input Mask property, the default entry for the field is The number is (###) ###-####. Then if you place the insertion point to the left of The and start typing numbers, the numbers replace the # placeholders, not the text. The Field Size setting is not applied to the characters in the mask, so if this setting is 15, the entry is not truncated even though the number of displayed characters (including spaces) is 28.
The > forces all following text to be uppercase. The L requires a letter. The < forces all following text to be lowercase. Each ? allows any letter or no letter, and there is one fewer question mark than the maximum number of letters you want to allow in the field (19, including the leading capital letter). The Field Size setting must be greater than this maximum.
As you can see, this type of mask has its limitations. But it can be useful in many situations.
Last Updated: Saturday, July 7, 2001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||