+ Reply to Thread
Results 1 to 4 of 4

Validating text box entry

  1. #1
    Registered User
    Join Date
    08-28-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    3

    Validating text box entry

    I've got an ActiveX text box and I'd like to validate what people type in it, and have a message box appear and the box cleared if the entry is invalid. The entry should only be validated once the user leaves the text box e.g. if they click on another part of the form.

    The text box entry should be a ten digit number.

    So far I have:

    Private Sub TEXTBOX_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not TEXTBOX Like "##########" Then
    MsgBox ("TEXTBOX should be ten digit number")
    End If
    End Sub
    When I put a four digit number into TEXTBOX, and click into another box, nothing happens.

    I'd also like the box to be cleared and the cursor placed back in the box so the user can have another shot at it. I'm using Excel 2007.
    Last edited by craigw04; 08-28-2013 at 10:50 AM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Validating text box entry

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-28-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Validating text box entry

    That worked fine, I'm very grateful.

    Is there something I can add to put the cursor back into the textbox after clearing it out?

    Also, Can you explain what the "Application.EnableEvents" lines do?

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Validating text box entry

    may be try this after the textbox1.activate

    Please Login or Register  to view this content.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

+ 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. Validating text box in Userform
    By hawkinsr86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2012, 08:08 AM
  2. Replies: 7
    Last Post: 07-09-2012, 11:48 AM
  3. Validating Entry Dates
    By braydon16 in forum Excel General
    Replies: 1
    Last Post: 12-06-2011, 10:11 PM
  4. Validating IP ranges / text
    By rokuk in forum Excel General
    Replies: 2
    Last Post: 02-04-2008, 04:38 PM
  5. Validating entry in ComboBox
    By LAF in forum Excel General
    Replies: 0
    Last Post: 09-29-2005, 03:45 PM

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