Share via


AllForms Collection [Access 2003 VBA Language Reference]

Multiple objects
AllForms
AccessObject
AccessObjectProperties

The AllForms collection contains an AccessObject object for each form in the CurrentProject or CodeProject object.

Using the AllForms Collection

The CurrentProject and CodeProject object has an AllForms collection containing AccessObject objects that describe instances of all the forms in the database. For example, you can enumerate the AllForms collection in Visual Basic to set or return the values of properties of individual AccessObject objects in the collection.

Tip

For Each...Next

You can refer to an individual AccessObject object in the AllForms collection either by referring to the object by name, or by referring to its index within the collection. If you want to refer to a specific object in the AllForms collection, it's better to refer to the form by name because a form's collection index may change.

The AllForms collection is indexed beginning with zero. If you refer to a form by its index, the first form is AllForms(0), the second form is AllForms(1), and so on.

Note  To list all open forms in the database, use the IsLoaded property of each AccessObject object in the AllForms collection. You can then use the Name property of each individual AccessObject object to return the name of a form.

You can't add or delete an AccessObject object from the AllForms collection.

The following example prints the name of each open AccessObject object in the AllForms collection.

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

Properties | Count Property | Item Property

Parent Objects | CodeProject | CurrentProject

Child Objects | AccessObjectProperties

See Also | AccessObject Object | CodeProject Object | CurrentProject Object