Create an input mask Access 2007

Author: mety Labels::



An input mask is a set of literal characters and mask characters that control what you can and cannot enter in a field. For example, an input mask can require users to enter dates or telephone numbers that follow the conventions for a specific country/region, like the following examples:
  • YYYY-MM-DD
  • (___) ___-____ xt. ___
When you place the focus on a field or control that contains an input mask, you may find that you can replace the placeholder characters with values of your own, but you cannot change or remove the literal or separator characters. For example, you may be able to fill in a date, but not change the hyphens that separate the sections of the date: 2006-01-09. In addition, an input mask can force you to enter data in one or more sections of the field or control. For example, if you enter a phone number but no area code in a mask (___) 555-0187 xt. ___ and try to save your changes, you cannot do so until you enter the area code. The exact behavior depends on the how the database designer sets up the input mask.
Because they can force you to enter data in specific ways, input masks provide a large amount of data validation. This means that they can help prevent users from entering invalid data (such as a phone number in a date field). In addition, they can 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.

When and where to use an input mask

You use an input mask whenever you want users to enter data in a specific way. For example, if you want users to enter phone numbers in the British format or German format, use an input mask.
You can add input masks to your table fields and form controls when it is logical to do so. 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. However, you cannot use input masks indiscriminately. By default, you can apply input masks to table fields that are set to the Text, Number (except ReplicationID), Currency, and Date/Time data types. You can also apply 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.
Note If you use an input mask for a Date/Time field, the Date Picker control is unavailable for use with that field.
You can add input masks to table fields by running the Input Mask Wizard, or by manually entering masks in a field property (the Input Mask property). You follow the same basic process when you add an input mask to a control on a form. For example, if you use the tools that Access provides to automatically create a form, the appropriate control inherits the input masks that you have applied to your table fields. You can also manually add input masks to the controls on your forms and, like tables, you add them to the Input Mask property of the control.

The components and syntax of an input mask

Input masks contain three sections, all separated by semicolons. The first section is mandatory, and the rest are optional. The following example is an input mask for telephone numbers in the U.S. format:
(999) 000-000;0;-
The first section defines the mask string and consists of placeholder and literal characters. The second section defines whether you want to store the mask characters and any data in your database. Enter 0 if you want to store the mask and your data. Enter 1 if you want to store only the data. The third section defines the placeholder that is used to indicate positions for the data. By default, Access uses the underscore (_). If you want to use another character, enter it in the third section of your mask. By default, a position accepts only one character or space.
In the preceding example mask, users must enter telephone numbers in the U.S. format. The mask uses two placeholder characters — 9 and 0. The 9 indicates an optional digit (you may not always enter an area code), and the 0 indicates a mandatory digit. The 0 in the second section stores your mask characters with your data, a choice that makes your data easier to read. Finally, the third section specifies the hyphen (-) instead of the underscore (_) as the placeholder character.

Differences between input masks and display formats

As you proceed, remember that you can define input masks and then apply a separate display format to the same data. For example, you can define an input mask that forces users to enter dates in a European format such as YYYY.MM.DD, but then you can apply a display format that rearranges the year, month, and day entirely. For example, the Medium Date display format renders dates as DD-MMM-YYYY, or 24-Aug-2006, regardless of how the input mask required you to enter the date originally. For more information about using display formats with your data.
Finally, remember that input masks and display formats can interfere with each other.

Enter an input mask in a table field

The steps in this section explain how to add an input mask to the Input Mask property in a table field. Remember that you can use input masks with fields that are set to the Text, Date/Time, Number (except ReplicationID), and Currency data types.

Add the input mask

  1. In the Navigation Pane, right-click the table that you want to change and click Design View on the shortcut menu.
  2. If the table doesn't contain a Text field, add one.
    1. In the upper section of the design grid, select a blank row, click the Data Type column, and then select Text.
    2. Save your changes and go on to the next steps.

  3. In the lower section of the design grid, on the General tab, click the Input Mask property box.
  4. Type the following input mask as shown:
    (999) 000-0000;0;_
  5. Click Save. Notice that Access adds several characters to your input mask:
    \(999") "000\-0000;0;_
    In this case, the backslashes and double quotation marks indicate literal characters. The first backslash forces Access to display the opening parenthesis. The double quotation marks force Access to display the closing parenthesis and the space that follows. The second backslash forces Access to display the hyphen that separates the first and second parts of the phone number. Alternatively, replace the backslashes with more double quotation marks, like so: "("999") "000"-"0000. An advantage of using backslashes instead of quotation marks (where possible) is that backslashes take up less space in the Input Mask property field on your screen.
  6. Switch to Datasheet view (right-click the document tab for the open table and click Datasheet View on the shortcut menu), and go to the next set of steps to test your mask.

Test an input mask

  1. Place the cursor in the field that contains your input mask.
    Notice that the mask appears only after you select the field.
  2. Add numbers and letters to the spaces in the mask.
    Notice that the mask accepts only numbers. If you try to add letters, Access prevents any characters from being entered because the 9 and 0 placeholders accept only digits.
  3. Remove a number from a space in the main body of the phone number, and then try to move the cursor to another field or otherwise save the record.
    Access displays an error message. The message appears because the 0 placeholder must contain a digit.
    The input mask error message
  4. Ask some general questions:
    • Will your mask prevent users from entering necessary data? For example, will users ever need to enter phone numbers in a format from another region?
    • Does your input mask interfere with your display formats? 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.

Add an input mask to a query

For more information about defining an input mask, click the InputMask property box, and then press F1. You must manually type the input mask definition for Number and Currency fields.

Add the input mask

  1. In the Navigation Pane, right-click the query that you want to change and click Design View on the shortcut menu.
  2. 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. Press F4 to open the property sheet for the field.
  4. Under Field Properties, on the General tab, click the Input Mask property box, and then do one of the following:
    • Click Build (...) to start the Input Mask Wizard, and then follow the instructions in the wizard.
    • Click the Input Mask field and type your input mask definition.

Add an input mask to a control on a form or report

  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. Right-click the control that you want to change, and then click Properties on the shortcut menu.
    The property sheet for the control appears.
  3. On the All tab, click the Input Mask property box, and then do one of the following:
    • Click Build (...)to start the Input Mask Wizard, and then follow the instructions in the wizard.
    • Click the Input Mask field and type your input mask definition.

Input mask character reference

The following table lists and describes the placeholder and literal characters that you can use in an input mask.
CharacterUse
0Digit. You must enter a single digit in this position.
9Digit. Single digits in this position are optional.
#Enter a digit, a space, or a plus or minus sign in this position. If you skip this position, Access enters a blank space.
LLetter. You must enter a single letter in this position.
?Letter. Single letters in this position are optional.
ALetter or digit. You must enter a single letter or digit in this position.
aLetter or digit. Single letters or digits in this position are optional.
&Any character or space. You must enter either a single character or a space in this position.
CAny character or space. Characters or spaces in this position are optional.
. , : ; - /Decimal and thousands placeholders, date and time separators. The character you select depends on your Microsoft Windows regional settings.
>All characters that follow appear in uppercase.
<All characters that follow appear in lowercase.
!Causes the input mask to fill from left to right instead of from right to left.
\Forces Access to display the character that immediately follows. This is the same as enclosing a character in double quotation marks.
"Literal text"Encloses any text that you want users to see in double quotation marks.
PasswordIn Design view for tables or forms, setting the Input Mask property to Password creates a password entry box. When users type passwords in the box, Access stores the characters but displays asterisks (*).

Examples of input masks

The examples in the following table demonstrate some of the ways you can use input masks.
This input mask Provides this type of valueNotes
(000) 000-0000(206) 555-0199In this case, you must must enter an area code because that section of the mask (000, enclosed in parentheses) uses the 0 placeholder.
(999) 000-0000!(206) 555-0199
( ) 555-0199
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.
(000) AAA-AAAA(206) 555-TELEAllows 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-20
2000
Any positive or negative number, no more than four characters, and with no thousands separator or decimal places.
>L????L?000L0GREENGR339M3
MAY R 452B7
A combination of mandatory (L) and optional (?) letters and mandatory numbers (0). The greater-than 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.
00000-999998115-
98115-3007
A mandatory postal code and an optional plus-four section.
>L<??????????????Maria
Pierre
A first or last name with the first letter automatically capitalized.
ISBN 0-&&&&&&&&&-0ISBN 1-55615-507-7A book number with the literal text, mandatory first and last digits, and any combination of letters and characters between those digits.
>LL00000-0000DB51392-0493A 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.

0 comments |

Labels

Blog Archive

Powered by Blogger.

I made these pages for me and my friends to help solving the problem we face regarding Computer & internet, if anyone wants me to answer a question or find out about some information please send me email and I will try to reply.*P.S. some of the article I wrote and the other I found on the internet I posted them in sprit of learning and shearing, please forgive me if you found something you don’t want to be in my blog, email me and I will delete them. Thank you for your interest in my pages.امل نجم Amal Nagm

banner 1 banner 2