Phone number input mask with default area code in Access

Applies to
Microsoft Access 97 and 2000

In Access, you cannot specify a default area code in an input mask for a phone number, but you can use the DefaultValue property of a field to specify a default area code that works with the input mask.

To specify the default area code and create a phone number input mask

  1. In Design view of the table, select the field that contains the phone numbers.
  2. In the lower portion of the window, enter the default area code in the DefaultValue box.
  3. Click the InputMask box , and then click the Build button (...) next to the box. When you receive a message asking if you want to save the table, click Yes.
  4. In the Input Mask Wizard, click Phone Number, and then click Next twice.
  5. Specify how you want to store the data, and then click Finish.
  6. To ensure that the default area code appears at the left of the input mask, delete the exclamation point (!) from the beginning of the field's input mask.

The new input mask and default area code are now in effect when you add a new record.

If you have a form that is based on this table, you might want to automatically position the cursor to the right of the area code when you press ENTER or the TAB key to go to the phone number control.

To position the cursor to the right of the area code automatically

  1. Open the form in Design view.
  2. Right-click the control that contains the phone number, and then click Properties.
  3. Click the Data tab, and make sure that the setting of the InputMask property matches the InputMask property of the corresponding field in the table.
  4. Click the Event tab, click the OnGotFocus box , and then click the Build button (...) next to the box.
  5. In the GotFocus event procedure for your phone number field, type the following text between the Sub and End Sub statements. Replace PhoneNumber with the name of the control on your form.
 Me![PhoneNumber].SelStart = 4
 Me![PhoneNumber].SelLength = 1
  1. Switch to Form view and press the TAB key to go to the phone number control. Note that the cursor automatically moves to the right of the area code.

For more information about input masks, type create an input mask in the Office Assistant or on the Answer Wizard tab in the Help window, and then click Search.

For more information about default values, type set a default value in the Office Assistant or on the Answer Wizard tab in the Help window, and then click Search.