+ Reply to Thread
Results 1 to 5 of 5

Limit number entry in Userform TextBox to exactly 6 digits

  1. #1
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Limit number entry in Userform TextBox to exactly 6 digits

    Hi

    I have a Userform where users need to enter a 6 digit reference number in Textbox1, is anyone aware how I can add code to the Textbox to only only 6 digits? and produce a message box if someone enters less or more than 6 digits?

    Many thanks

    Greg

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Limit number entry in Userform TextBox to exactly 6 digits

    Try this:- 3 codes for text box1
    !) To ensure numbers only
    2) To Ensure max Numbers = 6
    3) To let you Know if the Numers are less than 6
    Please Login or Register  to view this content.
    Last edited by MickG; 05-04-2014 at 09:15 AM.

  3. #3
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Limit number entry in Userform TextBox to exactly 6 digits

    Hi MickG

    Thanks for your reply.

    Parts 1 and 2 work perfectly, part 3 is almost there.

    If I enter less than 6 digits and click on the next textbox field positioned in the same frame as textbox1, I receive the message to enter 6 numbers, if I click on the Datepicker field, also in the same frame, I receive the error message however it then allows me to select a date and doesn't bring up the error message again. If I click on other textbox fields or comboboxes on the form which are positioned on a multipage I don't get the error message and I'm allowed to submit the form which then produces an email.

    If I then close or send the email, the userform closes which is correct, and sitting behind that I then have the message to advise to enter 6 numbers, so the message is populating however it's allowing me to complete fields positioned in the multipage element of the form and also submit the form

    Any thoughts?

    Thanks for your help

    Greg

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Limit number entry in Userform TextBox to exactly 6 digits

    I should just replace that last bit of code with something like below for each "Control code" in your Userform
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-07-2013
    Location
    Chester
    MS-Off Ver
    Home: 2011 for Mac Work: 2007
    Posts
    70

    Re: Limit number entry in Userform TextBox to exactly 6 digits

    Excellent, thanks MickG, got it working now

    Thanks again for your help

    Twaddy

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Wrong calculation results in userform textbox when using more than 3 digits for a number
    By Shacker in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-06-2013, 03:33 PM
  2. Excel 2007: Userform Textbox Prevent Number as the first entry
    By Hudas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2012, 02:48 PM
  3. [SOLVED] VBA UserForm - Have entry in TextBox fill Another TextBox by VLOOKUP
    By msquared99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2012, 10:24 PM
  4. Replies: 2
    Last Post: 07-09-2012, 02:05 AM
  5. to roundoff the digits for display in textbox of userform
    By taniks in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-21-2009, 10:54 AM

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