+ Reply to Thread
Results 1 to 14 of 14

If ElseIf statement

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    If ElseIf statement

    on sheets 5 i have in column B a list of employees names. In column C I have 4 digit pass codes.
    on the userform I have a combobox1 that list the names of the employees on sheet 5.
    Below this I have a textbox1 for current pass code. under this another textbox2 for new pass code.
    under this another textbox3 to confirm new pass word. What I am trying to do it if the two new pass codes <> the msgbox "Please try again". and allow the user to try again. here is what i have so far

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: if Eseif statement

    Please upload the workbook and offer some different examples of values that are in the combo and text boxes and what you expect to happen.

    Incidentally it's bad practice to use code like Sheets(5).Select, or even Sheets("Sheet5") since in the former case simply moving the position of the tab will cause the macro to fail, and changing the name of the sheet would cause the same problem. Always use the VBA sheet code name not the tab name or tab position.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: if Eseif statement

    Thanks Richard.
    so in textbox1 the user types in their current pass code.
    in textbox2 the user types in what they want the new pass code to be.
    in textbox3 the user confirms by retyping what they want the new pass code to be.
    when they hit the button it checks to make sure the new pass code (textbox2) matches the confirmed pass code(textbox3)
    if it does, then the pass code changes. If it doesn't, a message box pops up saying Please try again.
    Last edited by ColemanJames; 02-15-2018 at 01:51 PM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: if Eseif statement

    ColemanJames, I think the functionality was clear from your first post, but the reason we need your file is to see how your controls are designed, how you are using cells, and all of the code.

    The paper clip icon does not work for attachments. Instead, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    I can not upload due to confidentiality with my company. Let me make this easy.
    I need to know how to check if the value of two text-boxes match. If yes continue.
    If no allow user to reenter the pass code and check it again.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: If ElseIf statement

    Here is the best solution I can offer but without your file there is no way for me to test this and I have no idea if this will work with the rest of your code. Note that once the user enters this, he MUST enter two matching passwords. There is no way to quit.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    6StringerJazzer,
    That did not work. I have stripped down everything to the bare minimum.
    See if this will help. It is not exactly like what I have but enough that I can use the help with my code.
    Attached Files Attached Files

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: If ElseIf statement

    I am not seeing the problem with the original. If the user enters two passcodes that do not match, they get a message and the form stays up--it allows the user to try again. If they exit the form, the passcode is not changed. This is pretty much the industry standard. What do you want to do different?

    The benefit to using a GUI is that you have a lot more control over leading the user through entering input, and validation:

    • Disable the Change Passcode button until the user enters the correct current passcode and two matching new passcodes.
    • Do not allow the user to enter a new passcode until he has entered the current one correctly.
    • Do not allow the user to press the button until he has entered a correct passcode and two matching new passcodes.


    There is no need to insert a line in your sheet with the prompt, then delete after. You can add it directly to the combobox list when you load it.

    Also, I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.

    I have attached a rewrite that I think you will find gives a better user experience and greatly simplifies the code. You may have to address data types for your passcode field.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    the problem is, I try with wrong pass code to make sure the error comes up. (It does)
    the form stays up like I want.
    But second time I type correct code and it will still say incorrect.

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: If ElseIf statement

    That does not happen when I do it. If I delete the incorrect code and type the right one, the error goes away and the other two boxes become active.

  11. #11
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    your code works. But when I run it on my program as I start to type the second pass code (the first new one) I get the error

  12. #12
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    Your code does work and helps a lot. I figured my problem out and it was on my end. Everything is good now.
    Also, I have learned so much from you.
    Thanks so much.
    Last edited by ColemanJames; 02-16-2018 at 10:27 AM.

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: If ElseIf statement

    I'm glad to help! If you have further questions on this specific problem please post them to this thread.

  14. #14
    Registered User
    Join Date
    07-25-2017
    Location
    Oiho
    MS-Off Ver
    2010 standard
    Posts
    90

    Re: If ElseIf statement

    Thanks so much for your understanding and for all you have taught me.

+ 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. If ElseIf Else Statement not working
    By lazyserv in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-28-2015, 03:38 AM
  2. Adding CountIf Statement within If/ElseIf Statement
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2014, 05:09 AM
  3. [SOLVED] If...Then...ElseIf statement
    By BrownBoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2014, 05:19 PM
  4. Code stepping in to elseif statement when elseif is definitely not true
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2013, 05:31 PM
  5. If then elseif statement not working.........
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2011, 02:27 PM
  6. If then elseif statement
    By Mac10 in forum Excel General
    Replies: 3
    Last Post: 10-02-2010, 09:29 PM
  7. If then elseif statement help needed
    By Mac10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2010, 07:50 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