ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   unload or hide? (https://www.excelbanter.com/excel-programming/404167-unload-hide.html)

pswanie

unload or hide?
 
should i use unload userform1 or rather userform1.hide?


Bob Phillips

unload or hide?
 
Depends upon what you are trying to do.

If you think you will not use it again in this session, unload it.

If you think that you might use it again, and you don't want the Initialise
code called again, hide it.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"pswanie" wrote in message
...
should i use unload userform1 or rather userform1.hide?




Chip Pearson

unload or hide?
 
When you Hide a userform, the form is made invisible but it still resides in
memory so you can still access the values of the various controls that the
user changed. You would use Hide if your code needs to access the
userform's values after it is hidden. When you Unload a userform, the form
is made invisible and it is dumped out of memory. After an Unload, the
values on the form changed by the user are inaccessible and any attempt to
reference a control returm the default value (or possibly a error 91) of the
control (typically and empty string) rather than the value selected by the
user.

If you no longer need to get the values from a form once the user clicks
"Close", you should Unload the form. If, however, your code needs the
values from the form after it has been closed, use Hide and then once your
code is done with the form, Unload it. For example,

Sub AAA()
UserForm1.Show
''''''''''''''''''''''''''''''''''''''''''
' If the form is dismissed with Hide,
' we can still get the values from the
' form:
''''''''''''''''''''''''''''''''''''''''''
Debug.Print UserForm1.TextBox1.Text
''''''''''''''''''''''''''''''''''''''''''
' Once we Unload the form, the values from
' the controls are lost.
''''''''''''''''''''''''''''''''''''''''''
Unload UserForm1
Debug.Print UserForm1.TextBox1.Text
End Sub

Cordially,
Chip Pearson
Microsoft MVP, Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on th web site)

"pswanie" wrote in message
...
should i use unload userform1 or rather userform1.hide?




All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com