1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Private Sub TextBox1_Change()
Select Case Len(Me.TextBox1)
Case 1
If Me.TextBox1 Like "#" Then
Me.TextBox1 = "(" & Me.TextBox1
ElseIf Not (Me.TextBox1 Like "#") And Me.TextBox1 <> "(" Then
Me.TextBox1 = ""
End If
Case 2
If Not (Me.TextBox1 Like "(#") Then Me.TextBox1 = "("
Case 3
If Not (Me.TextBox1 Like "(##") Then Me.TextBox1 = Left(Me.TextBox1, 2)
Case 4
If Not (Me.TextBox1 Like "(###") Then
Me.TextBox1 = Left(Me.TextBox1, 3)
Else
Me.TextBox1 = Me.TextBox1 & ") "
End If
Case 5
If Not (Me.TextBox1 Like "(###)") Then Me.TextBox1 = Left(Me.TextBox1, 4) & "( "
Case 6
If Not (Me.TextBox1 Like "(###) ") Then Me.TextBox1 = Left(Me.TextBox1, 5) & " "
Case 7
If Not (Me.TextBox1 Like "(###) #") Then Me.TextBox1 = Left(Me.TextBox1, 6)
Case 8
If Not (Me.TextBox1 Like "(###) ##") Then Me.TextBox1 = Left(Me.TextBox1, 7)
Case 9
If Not (Me.TextBox1 Like "(###) ###") Then
Me.TextBox1 = Left(Me.TextBox1, 8)
Else
Me.TextBox1 = Me.TextBox1 & "-"
End If
Case 10
If Not (Me.TextBox1 Like "(###) ###-") Then Me.TextBox1 = Left(Me.TextBox1, 9)
Case 11
If Not (Me.TextBox1 Like "(###) ###-#") Then Me.TextBox1 = Left(Me.TextBox1, 10)
Case 12
If Not (Me.TextBox1 Like "(###) ###-##") Then Me.TextBox1 = Left(Me.TextBox1, 11)
Case 13
If Not (Me.TextBox1 Like "(###) ###-###") Then Me.TextBox1 = Left(Me.TextBox1, 12)
Case 14
If Not (Me.TextBox1 Like "(###) ###-####") Then Me.TextBox1 = Left(Me.TextBox1, 13)
Case Else
Me.TextBox1 = Left(Me.TextBox1, 14)
End Select
End Sub |
Partager