Is Form Open

Webskater

Registered User.
Local time
Today, 00:56
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 not one of the built in access functions. However it does come with the "Northwind sample database" If you click on help, you should see sample databases listed. Have a look at that, you should find function " is loaded" in there.

If not, post back here and I'm sure someone will have a copy.
 
"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.
 
IsLoaded Function from northwind database

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
 
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
 
>>> IsLoaded(ByVal strFormName As String) As Boolean <<<

To use this function you would do something like this:

If Isloaded ("YourFormName") then
'your code here
End If

This part: "ByVal strFormName As String" is asking for the form name as a string so you pass will form name like this: "YourFormName" (Between Quotes)

this part: As Boolean

means that the function IsLoaded with have one of two values it will either be "yes" or "no" Depending on whether the form is loaded or not.

This part of the if statement: If Isloaded ("YourFormName") then

"isloaded" is boolean so it Will either be yes or no.

So now you can read the if statement like this:

If Isloaded = Yes

If "Yes" then
'your code here (Runs your code)
End If

If Isloaded = No

If "No" then
'your code here (Your code Don't run!)
End If

I am not very good at explaining the "ByVal" bit of the code yet, however in a recent project I did have problems with a variable which using the "byVal" statement put right. So I am starting to get the hang of it! Will understand it well enough to explain it soon I hope.
 
Now that's why I thought it was such a strange question!

The "Isloaded property" you have provided a link to, shows a very poor example of its use. I found a better example here:

Code:
Sub AllForms()
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
    ' Search for open AccessObject objects in AllForms collection.
    For Each obj In dbs.AllForms
        If obj.IsLoaded = True Then
            ' Print name of obj.
            Debug.Print obj.Name
        End If
    Next obj
End Sub

To test it to see if I could get it working I tried:

Code:
Function test()
If Form_frmCalendar.IsLoaded Then
MsgBox "Loaded"
Else
MsgBox "Not Loaded"
End If
End Function

my test didn't work?
Produced the error: Method or data member not found (Error 461)
 
I've written a function that uses the access 2003 "IsLoaded" property To check to see if a form is loaded

Code:
Function fIsLoaded(ByVal frmName As String) As Boolean
    Dim obj As AccessObject, dbs As Object
    Set dbs = Application.CurrentProject
        ' Search for open AccessObject objects in AllForms collection.
        For Each obj In dbs.AllForms
            If obj.Name = frmName Then
                If obj.IsLoaded = True Then
                    fIsLoaded = True
                    Else
                    fIsLoaded = False
                End If
            End If
        Next obj
End Function

I'm sure you can use the is loaded property directly in your code, however I haven't worked out how to do that yet!
 
An apology to Mr. G Hudson!

I have just read my post and I noticed that my wording could be taken the wrong way!

>>> The "Isloaded property" you have provided a link to, shows a very poor example of its use. I found a better example here:<<<

I must apologize for the thoughtless wording! I am in no way annoyed with you! I was very annoyed with Microsoft for that particular example, fancy showing the isloaded event in conjunction with a data access page, it is a really stupid example, everyone uses isloaded to detect whether a form is loaded or unloaded.

I wrote to Microsoft in the feedback box provided and told them so. Microsoft examples are generally very good, I normally give them an eight or nine as feedback and I usually enter a positive comment, leaving my name and e-mail address as well. Which I did this time.
 
Last edited:
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
 
Without checking myself, (I am guessing) I think you need to search the forum for "IsOpen" if you have any problems post back

cheers Tony.
 

Users who are viewing this thread

Back
Top Bottom