Unload or Hide a UserForm
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Unload or Hide a UserForm
I was just wondering when using Unload or Hide of a UserForm, when is it best to one or the other. Let say if I go in and out of a UserForm1 frequently, would I just Hide, but if I were to selected a UserForm2 that is rarely used, would I then use Unload. Or does it even matter.
-
- Administrator
- Posts: 78524
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Unload or Hide a UserForm
It depends on how you use the form.
If you hide the form, it stays in memory, and all controls retain their value, as well as VBA variables. So when you show the form again, it will look exactly as when you hid it. The UserForm_Initialize event that ran when you first opened the form, will not run again when you unhide it.
If you unload a form, it is removed from memory. So when you open it again, all controls and variables have been cleared, and the UserForm_Initialize event will occur.
If you hide the form, it stays in memory, and all controls retain their value, as well as VBA variables. So when you show the form again, it will look exactly as when you hid it. The UserForm_Initialize event that ran when you first opened the form, will not run again when you unhide it.
If you unload a form, it is removed from memory. So when you open it again, all controls and variables have been cleared, and the UserForm_Initialize event will occur.
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1868
- Joined: 25 Jan 2010, 14:00
- Location: Conroe, Texas
Re: Unload or Hide a UserForm
Thank You Hans
-
- Administrator
- Posts: 12612
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Unload or Hide a UserForm
Also if you just hide a form then when you unhide it again it tends to change focus to the document that was active when you hid the form. I am not sure if this is the exact behaviour, but I do know that it is best to unload and reload the form if you care about which document has focus and you don't want to retain status in the form.
StuartR