Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you know if a form is loaded

Status
Not open for further replies.

monchet

Programmer
Jan 13, 2000
10
0
0
PH
What function can i use to determine if a certain form is loaded or visible [sig][/sig]
 
monchet,

As far as i know, there is no &quot;Built In&quot; function for &quot;Loaded&quot;. Depending on what you are trying to do, it (&quot;Loaded&quot; may not be necessary, since you may instantiate a form in VB in a number of ways - many with out showing it. [sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
 
What ho,

well, checking whether it's visible or not can be done by querying the form's .Visible property:

If Form1.Visible Then

and so on. However, it seems that forms are implicitly loaded whenever you try to access any of their properties or methods, so trying to see if it's loaded by querying it's .hWnd property or trying to treat it like an object (which is all it is in essence) and attempting a TypeName() function on it to see if it's loaded doesn't work, as it implicitly gets loaded so that it can perform your method or property call - stupid, overly helpful object!

Mind you, this is just what I've found and I may be wrong, so give it a go, you never know...

You might have to start looking into the Win32 API to see what there is in there to help...

Still, there you go,

Cheerio,


Paul
[sig][/sig]
 
You can query the form collection to see if the caption exists. The following snippet uses this principle to keep from opening the same form more than once. Can expand this to use the .visible property as well.
Code:
   Dim f As Form
   For Each f In Forms
      If f.Caption = &quot;frmMyForm&quot; Then Exit Sub
   Next
   Set f = New frmMyForm
   f.Show
[sig][/sig]
 
mixers approach is good - IF your program doesn't use the form caption property for other (variable) purposes. [sig]<p>MichaelRed<br><a href=mailto:mred@duvallgroup.com>mred@duvallgroup.com</a><br>There is never time to do it right but there is always time to do it over[/sig]
 
Use the tag property for testing:

Dim f As Form
For Each f In Forms
If f.Tag = &quot;frmMyForm&quot; Then Exit Sub
Next
Set f = New frmMyForm
f.Show

You have to remember to set the tag property for each form.

[sig][/sig]
 
Don't forget that you could use the name property..

Dim f As Form
For Each f In Forms
If f.name = &quot;frmMyForm&quot; Then Exit Sub
Next
Set f = New frmMyForm
f.Show

[sig]<p>David Paulson<br><a href=mailto: > </a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top