PDA

View Full Version : Text Box formatting.



austenr
11-04-2017, 08:17 PM
I have an activeX text box that I need to mask for phone number after entry. Hopefully like this (999)999-9999. I dont see a clear way to do it in the text box properties. Any ideas appreciated in advance.

Also, how do you do tab order for text boxes, not in a form?

Kenneth Hobs
11-04-2017, 08:54 PM
A class method might be needed if you have many of those. Otherwise:

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If vbTab = Chr(KeyCode) Then TextBox2.Activate
End Sub


Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If vbTab = Chr(KeyCode) Then TextBox3.Activate
End Sub


Private Sub TextBox3_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If vbTab = Chr(KeyCode) Then TextBox1.Activate
End Sub


Private Sub TextBox1_LostFocus()
TextBox1.Value = Format(TextBox1.Value, "(000)000-0000")
End Sub


Private Sub TextBox2_LostFocus()
TextBox2.Value = Format(TextBox2.Value, "(000)000-0000")
End Sub


Private Sub TextBox3_LostFocus()
TextBox3.Value = Format(TextBox3.Value, "(000)000-0000")
End Sub