+ Reply to Thread
Results 1 to 8 of 8

Textbox loop check to validate entry

  1. #1
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Textbox loop check to validate entry

    Sorry - rubbish title.

    I'm looking for some advice. I have 50 Textboxes on a userform and I wish to prevent a user from entering info in each one that begins with an 'I'. My code works fine but naturally I don't wish to have it repeated 50 times. How would I incorporate it into a loop and what would I call the Sub?

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Textbox loop check to validate entry

    You can do whats called event sinking, how are you with VBA?
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Textbox loop check to validate entry

    Hi Nathan,

    Out of 10? Probably a 5.

    Six on a good day!

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Textbox loop check to validate entry

    Ok, i'll tell you what to do and send a sample.

    You need the following in your userform

    Please Login or Register  to view this content.
    Then you need a class, called clsCustomTextBox, which has the code

    Please Login or Register  to view this content.
    What this does is pass every textbox on the form initialisation and diverts it to be our customtextbox, which is inherited from MsForms.Textbox, we just mess about with the events.

    HTH

  5. #5
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Textbox loop check to validate entry

    I see, thank you very much.

    I have a few questions if I may?
    • The class part. I have inserted a class module – is this what you mean?
    • Will your code apply to all textboxes? I have other textboxes where it’ll be ok for the user to start their TB entry with ‘I’. Although the ones I want it to apply to all share a similar naming pattern – could I use that? So instead of:


    Please Login or Register  to view this content.
    Could I use:

    Please Login or Register  to view this content.
    • Lastly I receive the following error upon compile (user type not defined):

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Textbox loop check to validate entry

    1 Yes it does, you will need to put after the if Typename line,
    Please Login or Register  to view this content.
    this will then omit the sinking for control1 and control2. Typename is the type name not the name.

    2 Have you named your class clsCustomTextbox?

  7. #7
    Forum Contributor
    Join Date
    08-23-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    404

    Re: Textbox loop check to validate entry

    That's great. Thanks a lot Nathan!! : )

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Textbox loop check to validate entry

    You could put this event code in the class module
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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] VBA to validate entry?
    By D_N_L in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-25-2014, 11:46 AM
  2. [SOLVED] VBA Validate textbox value to have alphanumeric characters
    By hydz1213 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-12-2013, 11:28 AM
  3. Check if textbox entry is in hh:MM format
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2009, 06:01 AM
  4. Validate a textbox
    By Digitborn.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2007, 03:46 PM
  5. Validate textbox entry
    By Stuart in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2005, 03:06 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