Computer and Software Support


About Input Masks

Microsoft Access

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, (___) 555-0187 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 hyphens.

  • 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.

  • 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.

 

Return to Input Masks