AllModules Collection

Microsoft Access Visual Basic

AllModules Collection

         
Multiple objects AllModules
AccessObject

The AllModules collection contains an AccessObject of each module in the CurrentProject or CodeProject object.

Using the AllModules Collection

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

Tip   The For Each...Next statement is useful for enumerating a collection.

You can refer to an individual AccessObject object in the AllModules 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 AllModules collection, it's better to refer to the module by name because a module's collection index may change.

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

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

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

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

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