Input Mask For SSN

  • Thread starter Thread starter Winston via AccessMonster.com
  • Start date Start date
W

Winston via AccessMonster.com

I have a data entry form that I'd like to mask the SSN like the password mask
with asterisks, all but the last 4. So, it would look like this: ***-**-0456

Does anyone know how to do this?

Thanks,
Winston
 
One way would be store the SSN in three fields, with three bound
textboxes. Use the "Password" mask on the first two textboxes.

Another would be to use an unbound textbox. In the textbox's KeyPress
event, capture the keystroke. Use the keystrokes (a) to accumulate what
the user types into a string variable, and (b) to substitute * for a
digit where necessary. Something vaguely like this (with a lot more
thought and testing needed):

Select Case KeyAscii

Case 48 to 57 'digits
strSSN = strSSN & Chr(KeyAscii)
If Len(Me.txtSSN.Text) <= 5 Then
KeyAscii = Asc("*") 'substitute *
End If

Case 8 'backspace
strSSN = Left(strSSN, Len(strSSN) - 1)

Case 9, 13 'tab, enter
'allow normal operation

Case Else
KeyAscii = 0 'ignore

End Select
 
Back
Top