Microsoft Access VBA Tutorials for self-paced learning, Class Modules, SQL Techniques, and AI Integration Guides.

Sunday, June 20, 2010

Input Masks and Data Entry

Input Masks and Data Entry.

Input masks are a special set of characters that can be applied to the Input Mask property of data fields in Microsoft Access to simplify data entry. They can also be used on Forms.

For example:

  • Text values can automatically convert to uppercase.

  • Slashes (/) can be inserted automatically in date formats to separate the day, month, and year.

  • Hyphens (-) can be inserted into telephone numbers to separate the country code, area code, and local number.

When entering large volumes of information manually, input masks greatly reduce effort, ensure consistency, and help maintain data in a standardized format for both entry and display.

Let us look at an example. Assume that we have a Text Field for entering Telephone Numbers, and the sample input mask Property setting is given below:

Input Mask of Telephone Number

(###) ###-#######;0;_

When the field is active before entering any values into the field, it will look like the display below:

(___) ___-____

The keystrokes you will make to type the telephone number are +914792416637, but the value will be automatically inserted in the appropriate segments, guided by the Input mask as (+91) 479-2416637. You don’t need to type the brackets, spaces, or hyphens that separate the country code, area code, and telephone number—these are inserted automatically by the input mask.

The Input Mask Property Value is expressed in three segments separated by semicolons.

The first segment value is the Input mask itself: (###) ###-#######.

The second segment value is 0 or 1. If the value is 1, the segment separator characters (brackets, spaces, and hyphens) are stored with the data in the field,  (+91) 479-2416637 (the field size must be large enough to store all the separator characters). If the value is 0, the keyed-in data alone is stored in the field as +914792416637, and the Input Mask is used for displaying the values.

The third segment value (the underscore character in the example) is used to indicate data entry positions with underscores.

When the Input mask character is # in all required character positions, it allows you to enter Digits, Spaces, plus, or Minus symbols only in the field, or leave the entire field empty.

The input mask character 9 works similarly, but it does not allow the use of plus (+) or minus (-) symbols in the data field.

The input mask character 0 restricts entry to digits 0–9 only, and, like 9, it does not permit plus or minus symbols.

Input Mask Date Field.

Input Mask Example2 (Date Field Input Mask): 99/99/0000;0;_

Sample Data Entry: _1/_1/1984 or 01/01/1984

Date value changes into 01/01/1984

In the Day and Month positions, you are allowed to enter a Space, but in the Year position, all four digits must be entered because the 0 input mask will not allow Spaces and cannot leave that area empty. But you can leave the Date Field totally empty.

Input Mask in Text Field.

Input Mask Example3 (Text Field): >CCCCCCCCCCCCCCC;0;_

Allows you to enter any Character or Space, or you can leave the data field blank. The Text Value entered will be converted to uppercase; you don't need to worry about the CAPS LOCK setting.

If you use the word Password as an Input Mask, then whatever data you enter into the field will appear as a series of * characters, and the actual value entered is not shown.

The list of Input Mask characters and their usage descriptions is given below.

Character    Description

0            Digit (0 to 9, entry required, plus [+] and minus [-] signs not allowed).

9            Digit or space (entry not required, plus and minus signs not allowed).

#            Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but blanks are removed when data is saved; plus and minus signs allowed).

L            Letter (A to Z, entry required).

?            Letter (A to Z, entry optional).

A            Letter or digit (entry required).

a            Letter or digit (entry optional).

&            Any character or a space (entry required).

C            Any character or a space (entry optional).

. , : ; - /  Decimal placeholder and thousand, date, and time separators (separator: A character that separates units of text or numbers.). (The actual character used depends on the settings in the Regional Settings Properties dialog box in Windows Control Panel).

<            Causes all characters to be converted to lowercase.

>            Causes all characters 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 the literal character (for example, \A is displayed as just A).

Password     Displays * in all keyed character positions.

You can use the above characters in mixed format to control or display field contents.

For example, the Input Mask>C<CCCCCCCCCCCCCC;0;_ will change the first character in uppercase and the rest of the text lowercase and accepts up to 15 characters in the field.

Technorati Tags:

Earlier Post Link References:

3 comments:

  1. Good post and this post helped me alot in my college assignement. Say thank you you as your information.

    ReplyDelete
  2. I need to know what vaule to enter for a name like McDonald. An autocap with the additional option to use Caps if needed but otherwise text remains in lowercase. Is this possible?

    ReplyDelete
  3. Input Masks cannot be conditional but with manual intervention (like button clicks or checkbox clicks etc.) it is possible with VBA.

    For McDonald like names set the Input Mask to ">L<L>L<????????????"

    For first letter cap and remaining characters in lower case: ">C<??????????????"
    For all upper case letters you can remove the < symbol.

    If the above Input Masks strings are required on the same textbox at your will then create two Command Buttons (cmd1 and cmd2) and add two Click Event procedures as given below:

    Private Sub cmd1_Click()
    Me.txtDisplay.InputMask = ">L<L>L<????????????"
    End Sub

    Private Sub cmd2_Click()
    Me.txtDisplay.InputMask = ">C<??????????????"
    End Sub


    The Input Mask string will be set to the txtDisplay Text Box depending on which command button you clicked before entering values into it. Even after entering value if you click the command button you can see the text changes.

    ReplyDelete

Comments subject to moderation before publishing.

Powered by Blogger.