+ Reply to Thread
Results 1 to 15 of 15

Dont Allow Empty Userform Fields

  1. #1
    Registered User
    Join Date
    02-07-2011
    Location
    Leeds
    MS-Off Ver
    Excel 2003-2007
    Posts
    8

    Exclamation Dont Allow Empty Userform Fields

    I have a userform and i need to make sure that when the user presses the add client button, it only adds the info from the userform to the sheet if all fields are filled.

    The code that i have at the minute doesnt allow you to proceed if a phone number has been added but i dont know how to make it work for multiple fields.

    Please Login or Register  to view this content.

    Any help will be greatly appreciated

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dont Allow Empty Userform Fields

    Why is the 'add client' button visible if not all compulsory textboxes have been filled ?



  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Dont Allow Empty Userform Fields

    Something like this:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Dont Allow Empty Userform Fields

    Here's an example to adapt
    Attached Files Attached Files
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    02-07-2011
    Location
    Leeds
    MS-Off Ver
    Excel 2003-2007
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    The reason that the button is available, is that i dont know how to make it not available when all the fileds are not filled.

  6. #6
    Registered User
    Join Date
    02-07-2011
    Location
    Leeds
    MS-Off Ver
    Excel 2003-2007
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    Quote Originally Posted by royUK View Post
    Here's an example to adapt
    I dont think that this is right for me.

    The code that i have works but only for one field. I dont know how to make it work for multiple fields.

  7. #7
    Registered User
    Join Date
    02-07-2011
    Location
    Leeds
    MS-Off Ver
    Excel 2003-2007
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    Quote Originally Posted by Domski View Post
    Something like this:

    Please Login or Register  to view this content.

    Dom

    I dont think that will work as it needs to be told to look at all the fields before allowing the sheet to be populated.

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Dont Allow Empty Userform Fields

    Mine was just an example and could be extended for as many fields as required.

    snb's suggestion is a good one to only make the button available once the fields are completed. I'm sure he'll provide you with an example of how to achieve this if you want.

    I'm off home now.

    Dom

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dont Allow Empty Userform Fields

    Please Login or Register  to view this content.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Dont Allow Empty Userform Fields

    Quote Originally Posted by Adam Hewitt View Post
    I dont think that this is right for me.

    The code that i have works but only for one field. I dont know how to make it work for multiple fields.
    Why it loops through controls & checks if they are complete. You can set the CommandButton's Visible or preferably Enabled Property according to the Function results

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Dont Allow Empty Userform Fields

    Personally I would just loop through all the textboxes and check them before proceeding; if you want to disable the button instead, I would use its enabled property rather than have it suddenly appear or disappear.
    Remember what the dormouse said
    Feed your head

  12. #12
    Registered User
    Join Date
    02-07-2011
    Location
    Leeds
    MS-Off Ver
    Excel 2003-2007
    Posts
    8

    Re: Dont Allow Empty Userform Fields

    i have tried the else if code that domski suggested and it just falls over and the debugger launches.

    I want it to look through all the fields and make sure that they are filled. if i could get the add button to appear when all the fields have been filed then that would be great but i dont know how to do that. As i am very new to this and quite basic at the minute any code that is posted, i would appreciate it if what the code is doing is explained.

    The best way that i can see this being achieved is if the code on the add button is looking through all the fields and if one of the fields is empty then do not allow the information to be added to the sheet. I would like the message box to say, for example, "please enter an email address and phone number".

    I want all empty fields to be named in the error message.
    Last edited by Adam Hewitt; 02-07-2011 at 01:03 PM.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: Dont Allow Empty Userform Fields

    Dom's code should work if you added it correctly, but it would be simpler to loop through all textboxes as snb did.

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dont Allow Empty Userform Fields

    I want tot warn all helpers:

    After 3 posts in this forum Adam Hewitt found it necessary to denunciate my question (that contained a solution implicitly) by a distraction to my reputation, adding 'Doesnt help answer the question'.
    I categorize this guy in the group of the 'too shortly fused'.
    Look for instance how gently he denounces other solutions.

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Dont Allow Empty Userform Fields

    Adam

    Giving negative rep because you either don't understand a solution is no way to get help.

    I've reversed the rep

    You seem to have an idea of what you need to do, but won't check suggestions that differ slightly.
    Attached Files Attached Files
    Last edited by royUK; 02-08-2011 at 04:21 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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