Formatting a text box in a form

J

JT

I have an input box for users to enter a 10 digit
telephone number (including area code).

Is there a way to format the text box so the hyphens are
automatically entered after the user keys in the 10
digits. I need the number to appear as follows:
123-456-7890

Thanks for the help.
 
R

Ron de Bruin

Hi JT

Try the Exit event of the textbox in the userform module

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Or Len(TextBox1) > 10 Then Cancel = True
Me.TextBox1.Text = Format(TextBox1, "000-000-0000")
End Sub
 
Top