+ Reply to Thread
Results 1 to 14 of 14

How do you unload only the top UserForm?

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    How do you unload only the top UserForm?

    Hi,

    When I have two UserForms open at the same time and I click on the "X" close button in the upper right hand corner of the top most form, ALL the forms unload. Is there code that changes that X button to only unload the form in which it resides and keep the other form loaded/shown?

    Thanks,

    Lawrence
    Last edited by skysurfer; 04-08-2010 at 10:58 PM.

  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: How do you unload only the top UserForm?

    Hello skysurfer,

    You should post your workbook. I have tried to reproduce this problem without success.
    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
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    Quote Originally Posted by Leith Ross View Post
    Hello skysurfer,

    You should post your workbook. I have tried to reproduce this problem without success.
    Hi Leith,

    Just got back and was preparing the workbook to be posted for you when I tested the issue...and there was no issue. That is, after shutting down Excel and then reloading the program and the workbook there is now no problem.

    However, I still would like to gain greater control over that X close button. Is it possible to apply code to it that will make the form hide instead of unload?

    Thanks!

    Lawrence

  4. #4
    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: How do you unload only the top UserForm?

    Hello skysurfer,

    The UserForm can tell if the close box was clicked or not.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    Thanks Leith.

    Where do I put that code? I tried it in the Forms and clicking on the X still unloads the UserForm. I'm trying to hide the form so when it is triggered to show again the last page on the MultiPage will be the 1st page seen.

    Lawrence

  6. #6
    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: How do you unload only the top UserForm?

    Hello skysurfer,
    1. Open the Visual Basic Editor and select a UserForm
    2. Press F7. This inserts the default event Private Sub UserForm_Click() into the UserForm.
    3. Above this window are 2 drop down lists. The one on the left is for Objects and the one on the right is for events.
    4. Click the righthand drop down list. Scroll down the list to QueryClose
    5. Insert the following line of code If CloseMode Then Me.Hide
    6. Repeat these procedures for each UserForm you want to hide instead of close.

  7. #7
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    Leith,

    I did that and the form hides when the X is clicked...I think.

    You see, there are 3 pages on the UserForm and I'm trying to get the form to re-open on the last page viewed. It does not behave that way with this code. Am I asking for the wrong solution? Is this even possible?

    Lawrence

  8. #8
    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: How do you unload only the top UserForm?

    Hello skysurfer,

    Like the Captain said in Coolhand Luke "What we got here is... failure to communicate." I think we are talking about 2 different things. If you post your workbook. it will put us both on the same page and I can answer your question.

  9. #9
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    Leith,

    I've attached a workbook with a simple MultiPage UserForm.

    Normally, when you unload a UserForm and then relaunch it, the page shown is the default page (usually page 1). Igt will always reopen to that same page.

    However, if instead you have a Close button that hides the form like in the attachment, relaunching the form will simply restore the form as it was when you last viewed it. That means if you were viewing page 2 when you hid the form, page 2 will be the same page you see when you show the form again.

    What I want to do is change the functionality of the X button on the top right corner of the form so that it has that same functionality: clicking it does not unload the form, but hides it.

    I hope that wasn't clear as mud. (BTW, Cool Hand Luke rocks!)

    Lawrence
    Attached Files Attached Files

  10. #10
    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: How do you unload only the top UserForm?

    Hello skysurfer,

    Coolhand Luke has always been one of my favorites. The MuliPage object remembers the last Page you selected. To force it to a particular page when the UserForm is displayed, add this to the UserForm. The MultiPage Pages are zero based. The first page is 0, the second is 1, etc.
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    Leith,

    What I'm after is a temporary bookmark. In my workbook, load the UserForm and select Page 2. Then, hit the "Close" button. when you click the "Show Userform" button again now you should be looking at Page 2. That's because the UserForm did not unload but was hidden.

    I want to apply that same functionality to the X button. Because if you hit THAT button, the UserForm unloads and forgets what page you were just looking at.

    So, I need the code that tells X NOT to unload the form, but to hide it.

    Lawrence

  12. #12
    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: How do you unload only the top UserForm?

    Hello skysurfer,

    This code will accomplish what you are after...
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How do you unload only the top UserForm?

    SUCCESS!!!

    Thank you!

    _______________
    Dragline: "Hell, he's a natural-born world-shaker."

  14. #14
    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: How do you unload only the top UserForm?

    Hello skysurfer,

    Glad we got it working. I like your signature line.

    Luke "Well, I don't care if it rains or freezes, long as I got my plastic Jesus, sittin' on the dashboard of my car.
    Comes in colors, pink and pleasant, glows in the dark cause it's irridescent."

+ 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