+ Reply to Thread
Results 1 to 2 of 2

exit sub when press cancel button on userform

  1. #1
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    exit sub when press cancel button on userform

    hi all,

    i have a userform with label, textbox, ok and cancel buttons.
    this userform is to prompt users for password.

    i use select case for capturing the password entered.
    case 1 is correct password
    case 2 is blank password which is vbnullstring
    case 3 is wrong password where i use case else

    when i click on cancel button, it will be detected as case else. cancel=true for my cancel button wont work.

    i think the logic is to put an IF statement before SELECT to capture if the cancel button is clicked.

    appreciate if anyone could help.

    thanks!

  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,258

    Re: exit sub when press cancel button on userform

    Hello hcyeap,

    Click the "Cancel" button shifts the focus from the "Password" text box. When the focus changes, all input is redirected to the control with the focus. Only events for the control with the focus are processed.

    Add this code to your "Cancel" button (change the name from Cancel to what you are using)...
    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
    Forum Contributor
    Join Date
    11-21-2013
    Location
    KL
    MS-Off Ver
    Excel 2010
    Posts
    168

    Re: exit sub when press cancel button on userform

    Hi Leith,

    Thank you for your suggestion!

    The modified code:

    Please Login or Register  to view this content.
    I have to add and End to make it work... don't know why... but as long as it works

    Thanks again!

+ 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] If cancel button is clicked then exit sub problem!?
    By jeroenft in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2014, 08:34 AM
  2. [SOLVED] user formm cancel button to exit multiple running subs
    By vijaysharmapc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2013, 02:55 PM
  3. Userform cancel button - how to exit multiple subs
    By sotiris5000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-16-2010, 09:56 AM
  4. [SOLVED] Userform SetFocus with Exit and Cancel
    By Neal in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2006, 09:25 PM
  5. [SOLVED] Looping procedure calls userform; how to exit loop (via userform button)?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2005, 08:05 AM

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