Determine if a userform is visible

R

Robert Crandal

Is this the only way to determine if a userform is
visible? :

if (Userform.Visible = true) then
' code here
end if

The problem with this code is that it seems to automatically
run the Userform_Initialize() routine. I'm wondering how
can I detect if a userform is visible without causing the
Userform_Initialize() routine to get invoked??

Thanks
 
W

witek

Robert said:
Is this the only way to determine if a userform is
visible? :

if (Userform.Visible = true) then
' code here
end if

The problem with this code is that it seems to automatically
run the Userform_Initialize() routine. I'm wondering how
can I detect if a userform is visible without causing the
Userform_Initialize() routine to get invoked??

Thanks
using "userform." will automaticaly trigger loading userform and
executing userform_initialize.

You can try that:

a) set a global variable to true in userform_initialize

b) read this http://www.ozgrid.com/forum/showthread.php?t=152892
(I did not try that just check)
 
G

GS

You can set a variable to a new instance of the userform and test its
existence...

Dim MyFrm As Userform
Set MyFrm = New Userform1 '//create an instance

If Not MyFrm Is Nothing Then...

...and in the case where you keep the userform loaded but not
necessarily visible...

If Not MyFrm Is Nothing Then MyFrm.Visible = True

Witek has another good suggestion that may be helpful in managing
multiple instances or a series of userforms. Though, where a series is
needed I prefer to use 'pages' on a single form because IMO it's easier
to manage multiple pages than multiple userforms<g>.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
R

Robert Crandal

witek said:
You can try that:

a) set a global variable to true in userform_initialize

Hi witek..... if I set my global variable to true in
Userform_Initialize(), won't this leave the possibly of
that variable being set to true even when the userform
is NOT actually visible?

I mean, if I run the following code then the variable
will be set to true while the form is not even visible:

' This code will run Userform_Initialize and
' cause my global variable to be set to true
'
if (Userform.Visible = true) then
' My code here
end if

If I set my global variable to true in Userform_Initialize(),
should I set it to false in Userform_Terminate()?
 
W

witek

Robert said:
Hi witek..... if I set my global variable to true in
Userform_Initialize(), won't this leave the possibly of
that variable being set to true even when the userform
is NOT actually visible?

I mean, if I run the following code then the variable
will be set to true while the form is not even visible:

' This code will run Userform_Initialize and
' cause my global variable to be set to true
'
if (Userform.Visible = true) then
' My code here
end if

If I set my global variable to true in Userform_Initialize(),
should I set it to false in Userform_Terminate()?


so do not use show. use your own code to show it at keep status somewhere.


load userform1
userform1.MyShow
unlaod userform1


and write myshow as part of userform1 with .show in it.
 

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

Top