+ Reply to Thread
Results 1 to 16 of 16

Userform Textbox Formatting

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

    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!

    Please Login or Register  to view this content.
    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 $.
    Please Login or Register  to view this content.

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

    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
    Posts
    974

    re: Userform Textbox Formatting

    Thanks Leith,

    This is what has gotten me the closest thus far:
    Please Login or Register  to view this content.
    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:
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021
    Posts
    974

    re: Userform Textbox Formatting

    Thanks to both of you (Ken & Leith) for taking the time to help with this. Ken I tried your code without success. The license number will always change, the format should however remain the same.

    Leith I'm attaching the workbook. I believe you should find the search portion (userform3) very familiar as you created it. It is userform1 specifically TextBox9 & TextBox14 that I need to be formated as reflected by the examples above the TextBox windows themselves. If that can be accomplished I need one other favor. I need to adjust the following code too, so that if either TextBox9 or if TextBox14 has data in it, it will put the textbox with data in column 5. i.e. Only one of those forms of ID can be used not both and whichever one has data needs to be put in column 5 on my data tab. I hope that makes sense. This is what I have but it isn't working quite right..
    Please Login or Register  to view this content.
    I almost forgot.. Leith the login and password is "pawn"
    Thanks!
    Last edited by lilsnoop; 03-03-2009 at 08:08 AM.

  9. #9
    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,

    I have had a lot of phone calls in the past hour. Deja vu! Will the prefixes for the ID and license always be (MI ID) and (MI)? If they are, would be okay to have the macro add them in if they are missing?

  10. #10
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021
    Posts
    974

    Re: Userform Textbox Formatting

    The prefixes will always be (MI) and (MI ID), and it would be great if the macro added them if they were missing! If another state ID or license is ever involved then I can edit the data tab for those rare occasions. Thanks again for the help!

  11. #11
    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,

    Forgot to ask this in the last post. Is the "A" in the ID and License always a single letter?

  12. #12
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021
    Posts
    974

    Re: Userform Textbox Formatting

    Hello Leith,

    Yes, In Michigan the license # or ID# will always start with the letter of the individuals last name. Thanks again!

  13. #13
    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

    You can always add the prefix ID letters in the Enter event for the textbox control.

    Most people typically validate the whole entry and then format it for input into the sheet. My earlier code just formatted the result assuming that the user entered data in one format. It did not check that the first three characters were letters.

    This code validates each character as it is entered. It then modified the entry according to what I think you wanted for the format.

    You can add some other Subs to make it more concise and/or add some Case Selects.

    Add this to the top line of the Userform code:
    Please Login or Register  to view this content.
    This is the exit event. You might want to add a part to make your other textbox Visible property equal False or Locked equals True if Len(TextBox9.Value)=21.
    Please Login or Register  to view this content.
    Here is the main part for Textbox9's Change event. Once your understand how it works, I would recommend that you clean it up and modularize it. When you see lots of similar IF's like this, Select Case and support Subs are usually a good idea. I generally do it the IF method until I see the repetitive pattern.

    You can use the same concepts in your other textbox. I also made each letter upper case.
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021
    Posts
    974

    Re: Userform Textbox Formatting

    Wow Ken, Thank you for the time you've put in helping me out. Works good for the license portion. I'll try and see if I can figure out the ID portion by altering your code.
    Last edited by lilsnoop; 03-02-2009 at 12:26 AM.

  15. #15
    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,

    I have added all the items on your wish list with the exception of the tabbing between empty text boxes. They are fully validated and correct the iput to the format you want. If it is incorrect, the user receives a message and is taken back to the text box with the entry highlighted. Here is the code for the text boxes. This has been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Valued Forum Contributor
    Join Date
    03-17-2007
    Location
    Michigan
    MS-Off Ver
    Excel 2021
    Posts
    974

    Re: Userform Textbox Formatting

    Thanks Leith & Ken for all your hard work!! It was much appreciated!

+ 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