+ Reply to Thread
Results 1 to 8 of 8

Userform Textbox Formatting

  1. #1
    Registered User
    Join Date
    01-08-2010
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Question Userform Textbox Formatting

    Hi all,

    I'm a bit stuck with one of my userforms. I have a username textbox on my workbook logon screen. I have put a max length on the textbox to 7 characters. I have also added a bit of code which stops the user from entering anything less than 7 characters (once the commandbutton is clicked, a msgbox comes up), and the textbox will show text in upper case.

    What I would like is a way to "format" the textbox. All of the usernames will be in the following format: BBAAA11. The first 2 characters will always be "BB". The 3rd, 4th and 5th characters will be any combination of letters (for example... "CAM", "EAL", "BEF"). Finally the last 2 characters will always be any combination of 2 digits (for example... "76" "24", "00").

    If someone could provide me with some code which will not allow the textbox to type anything other than the specified format, or for a msgbox to appear once the commandbutton has been clicked to say that the incorrect format has been entered, I will be most grateful.


    Thanks,

    LSM

    *cross posted @ http://www.mrexcel.com/forum/showthr...44#post2198644*
    Last edited by LSM1604; 01-31-2010 at 07:58 PM. Reason: Cross post update.

  2. #2
    Registered User
    Join Date
    01-10-2010
    Location
    Malmo, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Userform Textbox Formatting

    By using the character codes to check weather or not the parts of the string is number or letters. Simply make str to whatever is in the box.
    This should probably do it.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-08-2010
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Userform Textbox Formatting

    Excellent! Thanks to you, I will have no more head scratching over that problem!

    Thanks, much appreciated.

    LSM

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Userform Textbox Formatting

    Possibly try this? It should make wrong entries difficult!
    A few tweeks and it could be bullet proof!

    Add to your userform code, change the Textbox name to suit your needs.

    Please Login or Register  to view this content.

    You might want to add msgboxes to explain entry errors.

  5. #5
    Registered User
    Join Date
    01-08-2010
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Userform Textbox Formatting

    Hi Marcol,

    Thank you for taking the time to answer my post. Aron just pipped you to the post with a solution!

    LSM

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Userform Textbox Formatting

    No problem!

    None the less please have a look at the code - it demonstrates a stricter control over user entries, and the methods can be applied to any situation!

    Cheers.

  7. #7
    Registered User
    Join Date
    01-10-2010
    Location
    Malmo, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Userform Textbox Formatting

    Oh, forgot to say that this assumes that the text entered is in uppercase. It will get marked as wrong if it's "bb" instead of "BB" seems like Marcols code deals with both upper and lower case.

  8. #8
    Registered User
    Join Date
    01-08-2010
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Userform Textbox Formatting

    Hi all,

    The textbox is forced into upper case sing the following code:

    Please Login or Register  to view this content.
    Thanks for all your help.

    LSM

+ 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