+ Reply to Thread
Results 1 to 6 of 6

IF multiple textboxes in Userform = Nothing

  1. #1
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    IF multiple textboxes in Userform = Nothing

    Hi all,

    I have a spreadsheet which has a login userform and is password protected. one of the button I have within the sheet once you have logged in is the ability to add a user with certain access rights so they can also login if you wish.

    The userform is complete but I'm having trouble with the code (apologies the code is quite long) my 4 textboxes are the NewUseName, NewUseEmail, NewUseID and NewUsePassword, with the two option buttons determining which access to give to the new user.

    Please Login or Register  to view this content.
    I'm trying to get my code to read the contents of all 4 textboxes, if any of the boxes are empty and option 1 is selected then it will return a message box advising not all the fields have been completed (as they are all required), and then the same for option 2 being selected, any field empty display a message advising fields not completed, so long as all fields are completed, add the user!

    I tried stringing all the textboxes together at the start with the:

    If OptionButton1.Value = True And NewUseName & NewUseBRID & NewUseName & NewUsePass <> "" Then

    but this only returns the message box for option 1 and only looks for the NewUseName being empty, not the other boxes!

    Thanks in advance!
    Last edited by Catsonheat; 03-16-2017 at 04:17 PM.
    Excel Beginner

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: IF multiple textboxes in Userform = Nothing

    Having long IF ... Else ... End If blocks can obscure errors in the logic. Removing all the update lines gives
    Please Login or Register  to view this content.
    I'm sure you can see the issue in the Else block.

    When you want to check multiple controls you need to check each individually...
    Please Login or Register  to view this content.
    but you might find the following a little easier to follow
    Please Login or Register  to view this content.
    Last edited by cytop; 03-16-2017 at 04:51 PM.

  3. #3
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    Re: IF multiple textboxes in Userform = Nothing

    Hi Cytop, thanks for the response! that's worked great for the option1 however if I select option 2 it will display the message box saying a user has been added regardless if all fields are empty or populated.

    Here is what I have so far from your help above:

    Please Login or Register  to view this content.
    edited as I accidentally didn't post the full code
    Last edited by Catsonheat; 03-16-2017 at 05:19 PM.

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: IF multiple textboxes in Userform = Nothing

    select option 2 ... display the message box saying a user has been added
    That's what you've coded.

    If OptionButton2.Value is True and the 4 textboxes have been filled then the data is added. But it then protects the worksheet, hides the userform and shows the 'User Added' message.

    You need to add the Else block to display the message and exit the procedure if any textbox is blank, but to be honest the whole thing could be written better but that's a little difficult on a phone.

  5. #5
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    Re: IF multiple textboxes in Userform = Nothing

    oh yeah, sorry! I completely missed that Else at the end! still learning excel, this is one of the first codes I've written myself without posting for the initial code or stealing bits and pieces from code elsewhere all over the Internet until I got stuck at this point! happy I got a bit further before I got stuck though haha!

    thanks for your help! reputation added and marked as solved

  6. #6
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: IF multiple textboxes in Userform = Nothing

    2 important things to learn while learning to code - how to debug, and how handle errors...

    Both are as important as writing the code in the first place.

+ 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. VBA Userform Multiple Textboxes to Find Record
    By chamowllie01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-07-2016, 10:06 AM
  2. Format Multiple Textboxes at once in a Userform
    By Dan... in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2015, 05:34 PM
  3. Replies: 1
    Last Post: 02-17-2015, 07:11 AM
  4. [SOLVED] Code in userform to be flexible and work with multiple textboxes
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 01-21-2015, 11:04 AM
  5. [SOLVED] Changing multiple textboxes format on a userform
    By Raylou in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-12-2014, 10:11 AM
  6. Formatting Multiple Userform Textboxes
    By badeye in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-01-2010, 09:14 AM
  7. [SOLVED] Arrow key operation among multiple TextBoxes in a UserForm
    By George in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-13-2005, 11: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