+ Reply to Thread
Results 1 to 4 of 4

Unload UserForm Runs Initialize

  1. #1
    Registered User
    Join Date
    09-24-2009
    Location
    Atkinson, NH
    MS-Off Ver
    Excel 2003
    Posts
    23

    Unload UserForm Runs Initialize

    During execution of one of my applications, the user can go to a particular UserForm and change the units. For example, bar to psi. In order for the correct units (psi) to be displayed, all userforms that have pressure unit lables are unloaded (rather than hidden) so that when the userform is opened it will run the Initialize sub which changes the labels to "psi" for all the pressure inputs. The problem is that when the "Unload UserForm1" code is executed, it sometimes runs the Initialize sub before the UserForm is unloaded. I want the Initialize sub to always run when the UserForm is opened, not when it is closed. Is there a way to do this?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,979

    Re: Unload UserForm Runs Initialize

    That should only happen if the form had already been unloaded (it will effectively be loaded and then unloaded). If you used variables for your forms rather than using the default instancing, you should never run into that issue.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    09-24-2009
    Location
    Atkinson, NH
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Unload UserForm Runs Initialize

    Thanks for your reply. I understand the first half. Could you explain how to use variables for user forms? Also, is there any code that I can use to test if a userform is loaded or unloaded?

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,979

    Re: Unload UserForm Runs Initialize

    For the second part, you need to loop through the Userforms collection and check the names - for example:
    Please Login or Register  to view this content.
    To 'properly' use use userforms, rather than say using:
    Please Login or Register  to view this content.
    you use something like:
    Please Login or Register  to view this content.
    then when you want to unload the form:
    Please Login or Register  to view this content.

+ 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