+ Reply to Thread
Results 1 to 9 of 9

Commands after userform unload

  1. #1
    Registered User
    Join Date
    09-08-2014
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    7

    Commands after userform unload

    Hello,

    I have two userforms: userform1 and userform2. On userform1 I have button "next". After clicking it should close userform1 and open userform2. How to do this properly?

    For now I have:
    Please Login or Register  to view this content.
    It works. But I'm not sure if there should be additional commands after closing the form - after "unload me".
    What do you think about this?

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Commands after userform unload

    Hi there,

    See if the attached workbook does what you need.

    It uses the following code:

    Please Login or Register  to view this content.
    The first UserForm VBA CodeModule contains the routine:

    Please Login or Register  to view this content.

    The second UserForm VBA CodeModule contains the routine:

    Please Login or Register  to view this content.
    Each of the UserForms is loaded, displayed and unloaded by the main routine.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    09-08-2014
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    7

    Re: Commands after userform unload

    Thank you very much, but it was not exactly what it was about.
    On both forms I also have a cancel button that closes the forms. In your case - if I understand your code correctly (I've never seen such a code construction) - both forms are loaded and you hide the form when it is needed.
    In my case, second form can be loaded only if on first form is clicked next button, when is clicked cancel button simply first userform is unloaded and second form is not showing.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Commands after userform unload

    Hi again,


    (I've never seen such a code construction)

    Check out "Professional Excel Development", by Bovey, Wallentin, Bullen & Green


    Thanks for your last post - now that the picture is a bit clearer, see if the attached workbook does what you need.


    Also,


    - both forms are loaded and you hide the form when it is needed.

    No, this is not the case - once the first UserForm is displayed, control is transferred from the calling routine to the code in the first UserForm CodeModule. Control is returned to the calling routine only after the first UserForm has been hidden (by clicking on the "Next" button). It is only at this stage that the second UserForm is loaded and displayed.


    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files
    Last edited by Greg M; 02-16-2019 at 10:14 PM. Reason: Paragraph added

  5. #5
    Registered User
    Join Date
    09-08-2014
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    7

    Re: Commands after userform unload

    Hi again,

    And thank you again for your explanations and your help.
    Based on what you showed me, I prepared the modification. Does it make sense?

    Regards,
    Attached Files Attached Files

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Commands after userform unload

    Quote Originally Posted by Maverick71 View Post
    Hello,
    ...
    It works. ....
    What do you think about this?
    That's the key.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Commands after userform unload

    Hi again,

    Thanks for posting your latest version.

    Although your following code "works":

    Please Login or Register  to view this content.
    you are actually using the UserForm templates themselves rather than new instances of those UserForms. Good practice would create specific instances of the UserForms for use by your routine, for example:

    Please Login or Register  to view this content.
    Also, there's no need to name the "OK" Property of the second UserForm as "OK2" - the variables & properties used by each UserForm remain separated from each other, and when used in your calling routine each property will be prefixed by the variable which represents the specific UserForm (e.g. frm_2.OK), so there's no danger of the property values being "mixed up" by the calling routine.


    Hope this helps - feel free to ask if there's anything you want further information on.

    Regards,

    Greg M



    P. S. Regarding the previous post, there is a BIG difference between something that "works", and something that is well-designed!
    Last edited by Greg M; 02-17-2019 at 01:08 PM. Reason: P. S. added

  8. #8
    Registered User
    Join Date
    09-08-2014
    Location
    Netherlands
    MS-Off Ver
    2010
    Posts
    7

    Re: Commands after userform unload

    OK. I will correct it.
    Thanks for the great help.

    Regards

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Commands after userform unload

    Hi again,

    Thanks to you for all of your feedback and also for the Reputation increase - much appreciated!

    You're welcome - glad I was able to help.

    Best regards,

    Greg M

+ 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. Command button on userform to unload another userform?
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2017, 11:01 AM
  2. The userform doesn't seem to unload although I am using unload me line.
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-25-2014, 11:24 AM
  3. Unload all userform
    By danjim02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2013, 12:13 PM
  4. [SOLVED] userform will not unload with unload me
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2013, 12:09 PM
  5. [SOLVED] Userform called from another userform textbox - unload problem
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-27-2013, 01:09 PM
  6. ontime does not unload my userform
    By st0kvis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2010, 08:11 AM
  7. How do you unload only the top UserForm?
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-08-2010, 11:18 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