detecting whether any forms are loaded

  • Thread starter Thread starter Robert Smith
  • Start date Start date
R

Robert Smith

hello,
I have a piece of code that determines the active
form as follows:

Set frmCurrentForm = Screen.ActiveForm

However when there are no forms active you get the error
message,
You entered and expression that requires a form to be the
active window.

How do we determine if a form is the active window so that
we can avoid running this command if there are no forms
loaded.

Regards
Robert
 
Function IsLoaded(strFrmName As String) As Boolean

' Determines if a form is loaded.

Const conFormDesign = 0
Dim intX As Integer

IsLoaded = False
For intX = 0 To Forms.Count - 1
If Forms(intX).FormName = strFrmName Then
If Forms(intX).CurrentView <> conFormDesign Then
IsLoaded = True
Exit Function ' Quit function once form has been found.
End If
End If
Next

End Function
 
Back
Top