Container Object

Description

A Container object groups similar types of Document objects together.

Remarks

Each Database object has a Containers collection consisting of built-in Container objects. Applications can define their own document types and corresponding containers (Microsoft Jet databases only); however, these objects may not always be supported through DAO.

Some of these Container objects are defined by the Microsoft Jet database engine while others may be defined by other applications. The following table lists the name of each Container object defined by the Microsoft Jet database engine and what type of information it contains.

Container name

Contains information about

Databases

Saved databases

Tables

Saved tables and queries

Relations

Saved relationships


Note   Don't confuse the Container objects listed in the preceding table with the collections of the same name. The Databases Container object refers to all saved database objects, but the Databases collection refers only to database objects that are open in a particular workspace.

Each Container object has a Documents collection containing Document objects that describe instances of built-in objects of the type specified by the Container. You typically use a Container object as an intermediate link to the information in the Document object. You can also use the Containers collection to set security for all Document objects of a given type.

With an existing Container object, you can:

  • Use the Name property to return the predefined name of the Container object.
  • Use the Owner property to set or return the owner of the Container object. To set the Owner property, you must have write permission for the Container object, and you must set the property to the name of an existing User or Group object.
  • Use the Permissions and UserName properties to set access permissions for the Container object; any Document object created in the Documents collection of a Container object inherits these access permission settings.
Because Container objects are built-in, you can't create new Container objects or delete existing ones.

To refer to a Container object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:

Containers(0)

Containers("name")

Containers![name]

Properties

AllPermissions property, Inherit property, Name property, Owner property, Permissions property, UserName property.

See Also

User object.

Specifics (Microsoft Access)

In addition to the Container objects defined by the Microsoft Jet database engine, the following four Container objects are defined by Microsoft Access.

Container name

Contains information about

Forms

Saved forms

Modules

Saved modules

Reports

Saved reports

Scripts

Saved macros


The Container objects defined by Microsoft Access are Microsoft Access database objects, not Data Access Objects (DAO). These Container objects provide the Jet database engine with information about Microsoft Access objects. The Jet database engine uses this information to implement security on Microsoft Access database objects in the same way it does for DAO objects.

The Container objects defined by Microsoft Access and the Container objects defined by the Jet database engine are all included in the Containers collection in Microsoft Access.

The Documents collection of a Container object contains Document objects representing the individual objects of the type described by the Container object. For example, the Forms Container object has a Documents collection that might include a Document object corresponding to a form named Orders.

You can use Container objects to establish and enforce permissions for Microsoft Access database objects. To set permissions for a Container object, set the UserName property of the Container object to the name of an existing User or Group object. Then set the Permissions property for the Container object.

Note   Don't confuse the particular types of Container objects with the collection types of the same name. The Forms and Reports Container objects each contain Documents collections, which include individual Document objects representing each saved form or report. The Forms and Reports collections refer only to open forms or reports.

Example

This example enumerates the Containers collection of the Northwind database and the Properties collection of each Container object in the collection.

Sub ContainerObjectX()

    Dim dbsNorthwind As Database
    Dim ctrLoop As Container
    Dim prpLoop As Property

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")

    With dbsNorthwind

        ' Enumerate Containers collection.
        For Each ctrLoop In .Containers
            Debug.Print "Properties of " & ctrLoop.Name _
                & " container"

            ' Enumerate Properties collection of each
            ' Container object.
            For Each prpLoop In ctrLoop.Properties
                Debug.Print "    " & prpLoop.Name _
                    & " = " prpLoop
            Next prpLoop

        Next ctrLoop

        .Close
    End With

End Sub
Example (Microsoft Access)

The following example grants programmers full access to all modules in a database, and grants all other users read-only permissions on modules:

Sub SetModulePermissions()
    Dim dbs As Database, wsp As Workspace, ctr As Container
    Dim grp As Group

    ' Return reference to default workspace.
    Set wsp = DBEngine.Workspaces(0)
    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Return reference to Modules container.
    Set ctr = dbs.Containers!Modules
    wsp.Groups.Refresh
    For Each grp In wsp.Groups
        ctr.UserName = grp.Name
        If ctr.UserName = "Programmers" Then
            ctr.Permissions = ctr.Permissions Or dbSecFullAccess
        Else
            ctr.Permissions = ctr.Permissions Or acSecModReadDef
        End If
    Next grp
    Set dbs = Nothing
End Sub