-
Check this one out.
I would like my program to auto add a dash while typing in a Social Security Number.
Example: User types in "1 2 3" and then my program inserts the first - (dash) user then types in "4 5" and my program inserts the last - (dash).
I tried using the code below but it places my cursor at the start of the text box afterward.
'Private Sub TextSSN_KeyUp(KeyCode As Integer, Shift As Integer)
'If Len(TextSSN.Text) = 3 Then TextSSN = TextSSN & "-"
'If Len(TextSSN.Text) = 6 Then TextSSN = TextSSN & "-"
'End Sub
Do you have an idea on how this can be done and make the cursor go to the end of the text line?
Thanks for reading this.
-
Try this.
Code:
Private Sub TextSSN_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(TextSSN.Text) = 3 Then TextSSN = TextSSN & "-"
If Len(TextSSN.Text) = 6 Then TextSSN = TextSSN & "-"
TextSSN.SelStart = Len(TextSSN)
End Sub
-
Have you considered using the MaskEdit control instead of a regular TextBox?
If you want to go with a TextBox use this code:
Code:
Private Sub TextSSN_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(TextSSN.Text) = 3 Then
TextSSN = TextSSN & "-"
TextSSN.SelStart = Len(TextSSN.Text)
End If
End Sub
Good luck!
-
Beat me to the punch...
Man, you guys are too fast. By the way, I agree with Joacim about the masked edit control. However, I would alter his code a bit to include a length of 6 for the text box.
Code:
Private Sub TextSSN_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(TextSSN) = 3 or Len(TextSSN) = 6 Then
TextSSN = TextSSN & "-"
TextSSN.SelStart = Len(TextSSN.Text)
End If
End Sub
All the best.
[Edited by OneSource on 08-22-2000 at 11:38 AM]