How could one repackage this sub routine that triggers on the event _KeyPress and handles the field validation and returns the value back to the sub that called it or interacts directly with the field as Me.value.
the routine is mentioned in the following thread:
http://www.excelforum.com/excel-prog...-text-box.html
![]()
' Leith Ross Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim Char As Long Dim I As Long Dim N As Long If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0 Else For I = 1 To Len(TextBox1.Text) Char = Asc(Mid(TextBox1.Text, I, 1)) If Char >= 48 And Char <= 57 Then N = N + 1 Next I Select Case N Case 3 If Right(TextBox1.Text, 1) <> "-" Then TextBox1.Value = TextBox1.Value & "-" Case 6 If Right(TextBox1.Text, 1) <> "-" Then TextBox1.Value = TextBox1.Value & "-" Case 9 If Left(TextBox1.Text, 1) <> "(" Then TextBox1.Value = "(" & TextBox1.Value If Mid(TextBox1.Text, 5, 1) = "-" Then TextBox1.Value = Left(TextBox1.Value, 4) & ")" & Mid(TextBox1.Text, 6, 8) End If End Select End If End Sub











LinkBack URL
About LinkBacks
Register To Reply
Bookmarks