Function or method to test programmatically if specific form is op

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In VBA I want to open a form in particular circumstances and close it (if
it's open) in other cases. An error is generated if I try to close a form
that's not open. How can I test whether the form is open?
 
In VBA I want to open a form in particular circumstances and close it (if
it's open) in other cases. An error is generated if I try to close a form
that's not open. How can I test whether the form is open?

What version of Access?
Access 2000 or newer?

If Not CurrentProject.AllForms("FormA").IsLoaded Then
' It's not open. Do something here
Else
' It is open. Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) into a module:

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet view.

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

Then code some event:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if
 
Back
Top