Access Tip – Generic function to decide if a Form is open

The following are some samples of VBA code that may prove useful.

Another generic function that tells you if a form is open. If the form name was frmMyForm you would call it using something like:

If funIsLoadedForm(“frmMyForm”) = True then

         Do whatever you have to do

End If

Public Function funIsLoadedForm(ByVal strFormName As String) As Boolean
‘ Returns True if the specified form is open in Form view or Datasheet view.
On Error GoTo Error_funIsLoadedForm

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then

If Forms(strFormName).CurrentView <> conDesignView ThenfunIsLoadedForm = True

End If

End If

Exit_funIsLoadedForm:
Exit Function

Error_funIsLoadedForm:
MsgBox “Error in funIsLoadedForm: ” & Err.Number & ” – ” & Err.Description
Resume Exit_funIsLoadedForm

End Function