+ Reply to Thread
Results 1 to 16 of 16

Userform Textbox Formatting

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021 & 365
    Posts
    977

    Userform Textbox Formatting

    Could anyone offer advice on how I would go about accomplishing this task? I'm trying to format two textbox fields on my userform that when the user inputs data into it, it would automatically show the "symbols, dashes and/or spaces accordingling".

    The first textbox field (TextBox9) I need to end up looking like this, with the numbers and/or letters changing by user input.
    example: (MI) A000-000-000-000

    The next textbox Field (TextBox10) I need to end up with this type of result:
    example: (MI ID) A000-000-000-0

    I was trying something like this code: but I'm not familiar enough with the formatting symbols to accomplish this task. Any help would be appreciated!

    Private Sub TxtProperty_Exit(ByVal Cancel As MSForms.ReturnBoolean)
        TextBox9 = Format(TextBox9, "(##)&#000-000-000-000")
    End Sub
    Last edited by lilsnoop; 03-02-2009 at 02:54 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    re: Userform Textbox Formatting

    View your Custom numeric formats to see how they are done. Letters are $.
    TextBox9.Value = Format(TextBox9.Value, "($$) $000-000-000")

  3. #3
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021 & 365
    Posts
    977

    re: Userform Textbox Formatting

    Thanks Ken, I tried looking at the custom numeric formats but it didn't help.. especially when I need parentheses in my formatting as well... It seems quotes will need to be before and after my dashes, but the rest I'm still researching. Thanks for the letter symbol!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    re: Userform Textbox Formatting

    Hello lilsnoop,

    Move your code from the Exit event to the AfterUpdate event. That should help.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021 & 365
    Posts
    977

    re: Userform Textbox Formatting

    Thanks Leith,

    This is what has gotten me the closest thus far:
    Private Sub TextBox14_AfterUpdate()
    If Len(TextBox14) = 0 Then Exit Sub
    Select Case Len(TextBox1)
        Case 11
            TextBox14.Text = Format(TextBox14, "($$) $###-###-###-###")
        Case 10
            TextBox14.Text = Format(TextBox14, "($$ $$) $###-###-###-#")
        Case Else
            MsgBox ("Invalid License or ID format. Please try again."), , "Invalid Number"
            TextBox1.Text = ""
    End Select
    End Sub
    But, if someone types MID234000000000, I was hoping that after they hit the tab button it would put it in the format (MI) D234-000-000-000, etc.
    I'm thinking this isn't possible due to having spent at least 6 hours searching the web.. It appears most people want a userform textbox format for dates and/or currency related issues. Any other suggestions would be appreciated if you think this can be done.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    re: Userform Textbox Formatting

    Hello lilsnoop,

    Can you post your workbook? It would help answer some questions I have more quickly.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    re: Userform Textbox Formatting

    Try the Mid() method:
    Private Sub UserForm_Initialize()
      TextBox1.Value = "MID234000000000"
    End Sub
    
    Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
      Dim s As String
      With TextBox1
        s = .Text
        If Len(s) = 15 Then
          .Text = "(" & Mid(s, 1, 2) & ") " & Mid(s, 3, 4) & "-" & _
            Mid(s, 7, 3) & "-" & Mid(s, 10, 3) & "-" & Mid(s, 13, 3)
        End If
      End With
    End Sub

+ 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