AllForms object (Access)
The AllForms collection contains an AccessObject object for each form in the CurrentProject or CodeProject object.
Remarks
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.
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.
Example
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
The following example shows how to prevent a user from opening a particular form directly from the navigation pane.
'Don't let this form be opened from the Navigator
If Not CurrentProject.AllForms(cFormUsage).IsLoaded Then
MsgBox "This form cannot be opened from the navigation pane.", _
vbInformation + vbOKOnly, "Invalid form usage"
Cancel = True
Exit Sub
End If
Properties
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.