+ Reply to Thread
Results 1 to 4 of 4

Format A TextBox For A Phone Number

  1. #1
    Minitman
    Guest

    Format A TextBox For A Phone Number

    Greetings,

    I am trying to format a TextBox on a UserForm to display a phone
    number in xxx-xxx-xxxx format when I exit the TextBox.

    Any help would be appreciated.

    TIA

    -Minitman

  2. #2
    Tom Ogilvy
    Guest

    Re: Format A TextBox For A Phone Number

    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Textbox1.Text = format(textbox1.text,"000-000-0000")
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Minitman" <[email protected]> wrote in message
    news:[email protected]...
    > Greetings,
    >
    > I am trying to format a TextBox on a UserForm to display a phone
    > number in xxx-xxx-xxxx format when I exit the TextBox.
    >
    > Any help would be appreciated.
    >
    > TIA
    >
    > -Minitman




  3. #3
    Minitman
    Guest

    Re: Format A TextBox For A Phone Number

    Thanks Tom,

    That will do the trick.

    -Minitman

    On Tue, 8 Feb 2005 11:15:44 -0500, "Tom Ogilvy" <[email protected]>
    wrote:

    >Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    >Textbox1.Text = format(textbox1.text,"000-000-0000")
    >End Sub



  4. #4
    David Myle
    Guest

    Re: Format A TextBox For A Phone Number

    Try this-Tested!!:

    Private Sub TextBox1_Change()
    If Len(TextBox1.Text) = 3 Then
    TextBox1.Text = TextBox1.Text & Chr(45)
    End If
    If Len(TextBox1.Text) = 7 Then
    TextBox1.Text = TextBox1.Text & Chr(45)
    End If
    TextBox1.MaxLength = 12
    End Sub

    Should you want to apply this to a number of TextBoxes, use the modified
    version:

    Private Sub FormatText()
    Dim ctl As Control
    For Each ctl In Me.Controls
    If TypeName(ctl) = "TextBox" Then
    ctl.MaxLength = 12
    If Len(ctl.Text) = 3 Then
    ctl.Text = ctl.Text & Chr(45)
    End If
    If Len(ctl.Text) = 7 Then
    ctl.Text = ctl.Text & Chr(45)
    End If
    End If
    Next
    End Sub
    "Minitman" <[email protected]> wrote in message
    news:[email protected]...
    > Greetings,
    >
    > I am trying to format a TextBox on a UserForm to display a phone
    > number in xxx-xxx-xxxx format when I exit the TextBox.
    >
    > Any help would be appreciated.
    >
    > TIA
    >
    > -Minitman




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1