Conditional input mask

lhn

New member
Local time
Today, 14:53
Joined
Dec 7, 2009
Messages
1
I have a subform for collecting phone numbers. Each record consists of an employee ID, a phone type field, and a phone number field. On the phone "type" field, the user can select what type of phone number it is: home, work, cell, extension, beeper, etc, and then enter the actual number on the phone number field.

I would like to use different input masks depending on the phone type selection. I can do it using an After_Update event on the Phone Type field, however, it changes the mask for all the previous numbers.

For example, if I select "Home", the input mask is (000) 000-0000, but when I move to the next record and select "Extension" the input mask is "######" and my previous record (a home phone number) loses it's (000) 000-0000 mask.
 
As you've found, you cannot have conditional Input Masks like this on Datasheet or Continuous View forms. It's just like conditional formatting thru code, the current format applies to all instances of the field.

In a Single View Form, since you're only looking at one record at a time, you could do it by changing the Mask in the Form_Current event.

I would use a label placed strategically, to let the users know how to enter the phone number, with the label appearing only when the cursor was in the phone number textbox. In Design View after creating the label and naming it, set its Visible Property to No. The caption on the label can be changed depending on the value in the phone type field.

Code:
Private Sub PhomeNumber_GotFocus()
 Select Case Me.PhoneType
  
  Case "Home"
   Me.FormatLabel.Caption = "Please Input Number as (000) 000-0000"
  
  Case "Extension"
   Me.FormatLabel.Caption = "Please Input Number as 000000"
 
 End Select
   
 Me.FormatLabel.Visible = True
End Sub

Private Sub PhomeNumber_LostFocus()
 Me.FormatLabel.Visible = False
End Sub
 

Users who are viewing this thread

Back
Top Bottom