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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tell if a form is open or not 1

Status
Not open for further replies.

Kib

Programmer
May 17, 2001
58
US
How can I determine if a certain form is open or not in code?
Thanks
-Kib
 
This function returns a true/false answer to whether or not a form is open, paste it in a module and you're good to go:
[tt]
Function IsLoaded(ByVal strFormName As String) As Integer

IsLoaded = False
Dim frm As Form
For Each frm In Forms
If frm.Name = strFormName Then
IsLoaded = True
Exit For
End If
Next frm

End Function
[/tt]

Usage:
?IsLoaded("MyFormName")

HTH Joe Miller
joe.miller@flotech.net
 
hi,

might be a more appropriate way if you have many forms to loop trough:

SysCmd(acSysCmdGetObjectState, acForm, &quot;yourform&quot;) <> 0

then the form is open. (looks better too ;-))

CPU-burn
 
CPU,

Correct me if I'm wrong, but your way forces the system to go through every form and check it's object state from the msys tables. My way looks at the forms collection so it only looks at forms that are open, so this method is faster, because it will almost always have fewer forms to inspect that yours.

Joe Miller
joe.miller@flotech.net
 
sounds like you might be right.. maybe this s.t. to run a few test on next time I need it.. I'll keep your solution in mind!

CPUburn

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top