+ Reply to Thread
Results 1 to 14 of 14

Not Allow Empty Userform Fields

  1. #1
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Exclamation Not Allow Empty Userform Fields

    Quote Originally Posted by snb View Post
    Please Login or Register  to view this content.
    I don't understand this code. But it is VERY closely related to something I want to do. Could you post a generalized code to loop through 10 TextBoxes on a UserForm1; checking that every textbox has a value before proceeding to further functions?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will_P,

    Welcome to the Forum!

    I have provide you with 2 examples. The first assumes you have 10 TextBoxes total on the UserForm, and the second clears only 5 of the TextBoxes by name. I did not want to create 10 different TextBox names for an example.

    Whichever macro you use, add the code the UserForm in the General procedure section at the top of the UserForm.

    Example 1
    Please Login or Register  to view this content.
    Example 2
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    It's saying that Ctrl is not an object.
    Last edited by arlu1201; 04-17-2013 at 01:40 AM. Reason: Do not quote whole posts.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will_P,

    Can you post a copy of the workbook? Tell me which 10 TextBoxes needed to be checked and I will add the needed code.

  5. #5
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Unhappy Re: Dont Allow Empty Userform Fields

    GMD Request.xlsm

    I know I have a lot of messy macros on this workbook. Please forgive this great dishonor.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will_P,

    Here is the revised UserForm code...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    Will having

    Please Login or Register  to view this content.
    above

    Please Login or Register  to view this content.
    mess anything up?

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will,

    It is placed at the top (General procedures) so all Sub and Function routines on the UserForm can access it.

  9. #9
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    Ah, cool. That's another item on the list of things I learned today.

  10. #10
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    For the sake of myself and others; how do I make it not close and restart excel, if I press 'Submit' without filling out all the fields?

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will,

    Sorry, I din't catch that when I was fixing the macro. This should take care of the problem...
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    What do you think about this as an alternative? or something like this.

    Please Login or Register  to view this content.
    I want it to take you back to the form until you have filled it out or exited the form, at which point I'd want it to close the workbook. Also, if you submit with all the fields filled out, I want it to save and close. But I'd like a code word to access the data in the workbook. like if you put a codeword in one of the fields.
    Last edited by Will_P; 04-17-2013 at 12:20 PM.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Dont Allow Empty Userform Fields

    Hello Will,

    I am not sure I understand what you want to do. What should happen if Status is an empty string?

  14. #14
    Registered User
    Join Date
    01-24-2013
    Location
    Jackson, Mississippi
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    I solved it myself.

    Please Login or Register  to view this content.
    Last edited by Will_P; 04-17-2013 at 12:20 PM.

+ 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