Determine if Form is Open

crhodus

Registered User.
Local time
Yesterday, 23:20
Joined
Mar 16, 2001
Messages
257
I have two forms open at the same time, FORM ONE and FORM TWO. FORM ONE is invisible. FORM TWO is visible.

If I click on a button on FORM TWO, what code whould I need to use in order to determine if FORM ONE is open?

Thanks!
 
IsLoaded

Use the isloaded property:

From help screen:

IsLoaded Property

You can use the IsLoaded property to determine if an AccessObject is currently loaded. Read-only Boolean.

expression.IsLoaded

expression Required. An expression that returns one of the objects in the Applies To list.
 
I'm receiving an "Application-defined or object-defined error". This is the code I'm using:

If [Forms]![Form A].IsLoaded = True Then
MsgBox "IT WOKED"
Else
MsgBox "TRY AGAIN"
End If


Do I have something wrong?

Thanks for your help!
 
crhodus, are you running Access 97? If so, there is no IsLoaded property in that version. Instead use this function:
Code:
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 intX

End Function
 
Last edited:
Try this...
Code:
'Place this one in a public module
Public Function IsFormOpen(strFormName As String) As Boolean
    IsFormOpen = (SysCmd(acSysCmdGetObjectState, acForm, strFormName) = acObjStateOpen)
End Function
        
'Use this in your form
Private Sub Command1_Click()
    
    If IsFormOpen("fA") = True Then
    MsgBox "Form A is open"
        Else
        MsgBox "Form A is not open"
    End If
    
End Sub
HTH
 
Thanks to both of you for helping me. I tried ghudson's explanation first and it seems to be working.
 

Users who are viewing this thread

Back
Top Bottom