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

Determine if a Form is open

Status
Not open for further replies.

pcdaveh

Technical User
Sep 26, 2000
213
US
I'm running a report. The criteria for this report is comes from a form. If the form is not open meaning that the criteria isn't there then I want the user to be propted that they must take this initial step described above first. So, again I need a bit of code that will tell me if a form is open before the report shows errors. Determine if a form is open?
 
This function will return a True/False answer about whether a form is open or not:
[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
End If
Next frm

End Function
[/tt]

Place it in a module and then it's usage is like so:
[tt]
If IsLoaded("MyFormName") = True Then
'Run code for loaded form
End If
[/tt]

HTH Joe Miller
joe.miller@flotech.net
 
Joe, your code will work fine, however it has to loop through every form in the forms collection. The following will be a little quicker, especially if you have a lot of forms in your db:

====================
Function IsLoaded(ByVal strFormName As String) As Boolean
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
====================

To Use it:

If IsLoaded(&quot;MyForm&quot;) Then
Run Code
End If

Nothing against your code, again, just one more option. Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Jim, you're absolutely right, I found that function ages ago before I started coding myself and have never actually inspected it until just now when you said that. If I add an Exit For in there I'll have slowed it down considerably.

Joe Miller
joe.miller@flotech.net
 
Jim, you're absolutely right, I found that function ages ago before I started coding myself and have never actually inspected it until just now when you said that. If I add an Exit For in there I'll have speeded it up considerably.



Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top