closing a userform

M

mangesh_yadav

I have a case where my userform could either be open or closed. How do
find in which state it is. For example, if the userform is closed and
try to close it, it is first initialised and then closed, which I don
want to do.

- Manges
 
G

GJones

Hi Mangesh;

You can create a seperate sub that includes an error
handling event. Call the form with either load or show
and then you'll know it is open. If you want it closed
then use unload and if you want it open then leave it as
show.

Thanks,

Greg
 
M

mangesh_yadav

First of all, thanks for the reply. Yes, but the problem is that when
want to close it, and its already closed, then I don't want to open i
first and then close it. Currently, thats how I am handling it.

- Manges
 
T

Tom Ogilvy

If it is loaded, then it will be in the userforms collection

for each frm in Userforms
if frm.name = "MyUserform" then
unload frm
end if
Next

If you reference a userform and it is not loaded, then it is immediately
loaded (as you have observed/stated). This should avoid that.
 
T

Tom Ogilvy

also, if you only have one form, you can look at

Userforms.count

as an indicator as well.
 
Top