Determine if a form is open

  • Thread starter Thread starter Christopher Eberhart
  • Start date Start date
C

Christopher Eberhart

I am usign Access 2000. How can I programatically
determine if a particular form is open?

I just know that this must be posible but I cannot find
anything the the Knowledge Database of Access help.
 
I've always used this user defined function (from Ken Getz, I believe):

Public Function IsOpen(strName As String, Optional varObjectType As Variant)
'Returns True if strName is open, False otherwise.
'Assume the caller wants to know about a form.
If IsMissing(varObjectType) Then varObjectType = acForm
IsOpen = (SysCmd(acSysCmdGetObjectState, varObjectType, strName) <> 0)
End Function

However, Access XP and 2003 have a new function you can use. I don't
remember is 2000 has it or not.
Here is an example from the help file for that.

Sub AllForms()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name
End If
Next obj
End Sub
 
Christopher Eberhart said:
I am usign Access 2000. How can I programatically
determine if a particular form is open?

I just know that this must be posible but I cannot find
anything the the Knowledge Database of Access help.

I haven't tried it, but you should be able to do a For Each ... Next through
the Forms collection to see if a particular Name is listed. The Forms
collection refers to forms that are currently open.
 
Yes - Allforms was added in Access 2000.

if CurrentProject.allforms("form1").isloaded then
msgbox "Form1 is loaded"
endif
 
Back
Top