+ Reply to Thread
Results 1 to 9 of 9

Did user hit the close button in my userform?

  1. #1
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    293

    Did user hit the close button in my userform?

    If I have a check box on sheet1, that once it equals true, that a userform is activated.

    Now within that userform, the user MUST fill out that data if the checkbox on sheet1 is to remain true. (This is ideal and is what I want to have happen).

    But currently, if the user hits the red X close button at top right, it will indeed unload the userform and close it (as it should), BUT the check box remains checked.

    How do I trap to see if the user hit the close button and if they did, to uncheck the box on sheet?
    Last edited by clemsoncooz; 02-06-2012 at 03:22 PM.

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Did user hit the close button in my userform?

    Hi

    Userform's have a QueryClose event where you can trap how the userform is closed eg in your case:

    Please Login or Register  to view this content.
    CloseMode can be one of the following:

    vbFormControlMenu 0 The user has chosen the Close command from the Control menu on the UserForm.
    vbFormCode 1 The Unload statement is invoked from code.
    vbAppWindows 2 The current Windows operating environment session is ending.
    vbAppTaskManager 3 The Windows Task Manager is closing the application.

  3. #3
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    1,955

    Re: Did user hit the close button in my userform?

    not sure, but you can try to use "noXclose" and ffrom a button to unload the userform and uncheck the checkbox?!

    edit: sorry....
    Last edited by john55; 02-06-2012 at 03:07 PM. Reason: late reply
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  4. #4
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Did user hit the close button in my userform?

    Thank you very much Firefly. So far, that appears to be just what I was talking about!

    But you lost me with this, as I do not know what you are talking about here:
    CloseMode can be one of the following:

    vbFormControlMenu 0 The user has chosen the Close command from the Control menu on the UserForm.
    vbFormCode 1 The Unload statement is invoked from code.
    vbAppWindows 2 The current Windows operating environment session is ending.
    vbAppTaskManager 3 The Windows Task Manager is closing the application.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,077

    Re: Did user hit the close button in my userform?

    Hi clemsoncooz,

    What Firefly2012 gave you is great.

    In the Declarations part of the UserForm you could also add the following code, which prevents the UserForm from being dragged out of the way etc. It will just sit there, until the code completes. However, you may still need to include Firefly2012's code to set the "Checkbox" value to false.

    Please Login or Register  to view this content.
    Hope it helps!
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Did user hit the close button in my userform?

    Quote Originally Posted by clemsoncooz View Post
    Thank you very much Firefly. So far, that appears to be just what I was talking about!

    But you lost me with this, as I do not know what you are talking about here:
    CloseMode can be one of the following:

    vbFormControlMenu 0 The user has chosen the Close command from the Control menu on the UserForm.
    vbFormCode 1 The Unload statement is invoked from code.
    vbAppWindows 2 The current Windows operating environment session is ending.
    vbAppTaskManager 3 The Windows Task Manager is closing the application.
    I just meant you can use those constant values (such as vbFormControlMenu) to check how the Userform is being closed. In your case you can safely ignore everything beyond the code snippet provided.

  7. #7
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Did user hit the close button in my userform?

    Thanks Winon, but when you say "In the Declarations Part of the userform," maybe this is just a terminalogy confusion, but I am not sure what/where you mean to put this.

    Same location as the rest of my code for that userform?

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,077

    Re: Did user hit the close button in my userform?

    Right at the top of the Code Page for your UserForm, Before Anyting other code, you Copy and Paste, what I gave you.

    Please just make sure "Option Explicit" does not appear twice, right at the top. If it does, delete one of them.

  9. #9
    Forum Contributor
    Join Date
    12-20-2011
    Location
    United States, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    293

    Re: Did user hit the close button in my userform?

    OK - thank you everyone!

+ 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