+ Reply to Thread
Results 1 to 7 of 7

VBA Userform - Textbox Validation

  1. #1
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    VBA Userform - Textbox Validation

    I am trying to make it so that a client's last name cannot be blank on a userform.

    I think i am close to getting it to work properly... but I keep getting a "Subscript out of range" error. Any thoughts on what I am doing wrong??


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Microsoft 365 Subscription
    Posts
    120

    Re: VBA Userform - Textbox Validation

    Try changing to this

    Please Login or Register  to view this content.

  3. #3
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Userform - Textbox Validation

    I just changed it to that And I was able to tab through the field... never received and error and was able to save the data to the sheet... again never getting an error.

    That being said, I just tested a phone number box as well, and again could tab past it without getting an error.. and saved the line item without a problem.


    Please Login or Register  to view this content.
    File attached here....
    Attached Files Attached Files

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

    Re: VBA Userform - Textbox Validation

    The AfterUpdate event fires only if the contents of the textbox are changed while it has the focus. Tabbing through the text box will not fire that event.

    The verification that there is a last name should take place when the Submit button is pressed. Not as part of the textbox's event code.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Microsoft 365 Subscription
    Posts
    120

    Re: VBA Userform - Textbox Validation

    mikerickson, dumby me I did not even look at that part of the code. Mine is in the Submit Button and I knew it was working correctly so just replied quickly to try and help because I just finished setting up a userform a few minutes ago with validating 6o different textboxes.

  6. #6
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Userform - Textbox Validation

    Got it... so when the button is pushed is when i add it in.

    So the button is a "next page" button that has the following code

    Please Login or Register  to view this content.
    Do I just make it say




    Please Login or Register  to view this content.

  7. #7
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Userform - Textbox Validation

    I tried it and the answer is yes, except for I left out an Exit Sub.

    Here is the code working in case anybody else needs it.

    Please Login or Register  to view this content.

+ 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] UserForm TextBox Validation for Whole Numbers
    By ptmuldoon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-14-2022, 08:08 PM
  2. Userform textbox validation - non-existent date validation
    By rbngrt582 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2018, 10:14 PM
  3. Userform Textbox validation dependent on another userform
    By Amita68 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-23-2017, 08:20 AM
  4. [SOLVED] excel userform textbox validation
    By aarona in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2017, 04:33 AM
  5. Userform textbox validation for all boxes
    By Rob K in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-18-2015, 06:57 AM
  6. Validation of Textbox on Userform
    By bigfishprf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2015, 01:52 AM
  7. Data Validation in textbox on userform
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2013, 07:37 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