Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Check If A Form Is Loaded?

Form Basics

How To Check If A Form Is Loaded?

by  Schof  Posted    (Edited  )
[blue]The function below takes the name of a form as an input parameter and returns True/False if the form is loaded.

There is a second optional parameter that allows you to specify (by setting value to True that you want to know whether there is another form loaded other than the one specified in the first parameter.

Place the code in a module and call it using something like:[/blue]

If formIsLoaded("MyForm") Then [green]' MyForm is loaded[/green]

If formIsLoaded("MyForm", True) Then [green]' Some other form other than MyForm is loaded[/green]


Code:
'-----------------------------------------------------------
' FUNCTION: formIsLoaded
'
' Determines whether the specified form OR
' another form other than the one specified
' is loaded.
'-----------------------------------------------------------
'
Public Function formIsLoaded(ByVal vstrForm2Check As String, Optional ByVal vblnExcludingForm2Check As Boolean = False) As Boolean
On Error GoTo Err_formIsLoaded

    Dim aobForm As AccessObject

    For Each aobForm In Application.CurrentProject.AllForms
        If aobForm.IsLoaded Then
            If aobForm.name = vstrForm2Check And vblnExcludingForm2Check = False Then
                formIsLoaded = True
                Exit Function
            ElseIf aobForm.name <> vstrForm2Check And vblnExcludingForm2Check = True Then
                formIsLoaded = True
                Exit Function
            End If
        End If
    Next aobForm
    
    formIsLoaded = False
    
Exit_formIsLoaded:
    Exit Function

Err_formIsLoaded:
    MsgBox Err.Description
    Resume Exit_formIsLoaded
    
End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top