Is Form Open

Webskater

Registered User.
Local time
Today, 13:58
Joined
Aug 29, 2006
Messages
14
Hi

I know this is stupid but ... I looked in my book and it said it you want to test whether a form is open you can do this ...

If FormName.IsLoaded = True Then

If I try this it tells me 'IsLoaded' is not a valid property.

How do you test if a specific form is open?

Cheers
 
"IsLoaded" is a Function in "Northwind.mdb", Modules, Utility Functions.
Try to find "Northwind.mdb" on your PC and copy this function in your mdb.
 
Uncle Gizmo said:
Here it is:

Code:
Function IsLoaded(ByVal strFormName As String) As Boolean
 ' Returns True if the specified form is open in Form view or Datasheet view.
    Dim oAccessObject As AccessObject

    Set oAccessObject = CurrentProject.AllForms(strFormName)
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then
            IsLoaded = True
        End If
    End If
    
End Function

Thanks very much for your answers. I wonder if you can help me understand something. The function is called IsLoaded

You dim oAccessObject as an 'AccessObject'

You then write ...

If oAccessObject.IsLoaded Then

... which I don't understand. Is 'IsLoaded' a property of an Access object?

Cheers
 
Searching really does work! I found this on another thread. Freakazeud gets the credit for this simple yet effective [Access 2003] solution for testing if a form is loaded...

Code:
Public Sub Test()
On Error GoTo Err_Test

    If CurrentProject.AllForms("YourFormName").IsLoaded Then
        MsgBox "Yes, the form is open."
    Else
        MsgBox "No, the form is not open."
    End If

Exit_Test:
    Exit Sub

Err_Test:
    If Err.Number = 2467 Then 'The expression you entered refers to an object that is closed or doesn't exist.
        MsgBox "The form you are testing if open does not exist.", vbCritical, "Invalid Form"
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_Test
    End If

End Sub
 
Can you do the same but for a report??

I have a button that runs a report, but it falls over if the report is still open and it is run again.

Does IsLoaded work for a report too, so that you can say

If Report is open then close report and run report again, otherwise just run the report
 

Users who are viewing this thread

Back
Top Bottom