closing a userform

  • Thread starter Thread starter mangesh_yadav
  • Start date Start date
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
 
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
 
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
 
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.
 
also, if you only have one form, you can look at

Userforms.count

as an indicator as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top