>
Container Object
Description
A Container object
groups similar types of Document objects together
for example, one container might have Tables documents.
Applications can define their own document types and
corresponding containers.
Remarks
Each Database object has
a Containers collection consisting of built-in Container
objects. 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 Jet database engine and what type of
information it contains.
Container
name |
Contains
information about |
|
Databases |
Containing database |
Tables |
Saved tables and
queries |
Relations |
Saved relationships |
Note
Don't confuse the particular
types of Container objects listed in the preceding table
with the collection types of the same name. The Databases type of
Container object refers to all saved objects of the
specified type, but the Databases collection refers only
to open objects of the specified type.
Each Container object
has a Documents collection that contains a Document
object for each instance of the type of object it describes. You
typically use a Container object with one of the Document
objects in the Documents collection, so you can consider a
Container object to be an intermediate link to the
information that the Document object contains.
Because Container
objects are built-in, you can't create new Container
objects or delete existing ones. Using the properties of an
existing Container object, you can:
-
Determine the predefined names an
object has by checking its Name property setting.
-
Determine or specify the owner of
the Container object by checking or setting its Owner
property. 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.
-
Set access permissions for the Container
object using the Permissions and UserName
properties; any Document object created in the Documents
collection of a Container object inherits these
access permission settings.
You can refer to a Container
object in a collection by its ordinal number or by its Name
property setting, using either of the following syntax forms:
Containers(0)
Containers("name")
Properties
AllPermissions Property,
Inherit Property, Name Property, Owner
Property, Permissions Property, UserName Property.
See Also
User Object; Appendix,
"Data Access Object Hierarchy."
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. 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 data access 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
properties of all the Container and Document
objects in the current database.
Function EnumerateDocuments () As Integer
Dim dbsCurrent As Database
Dim conTest As Container, docTest As Document
Dim intC As Integer, intD As Integer
Set dbsCurrent = _
DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
For intC = 0 To dbsCurrent.Containers.Count - 1
Set conTest = dbsCurrent.Containers(intC)
Debug.Print ">> Container: "; conTest.Name;
Debug.Print " Owner: "; conTest.Owner
Debug.Print " UserName: "; conTest.UserName;
Debug.Print " Permissions: "; conTest.Permissions
Debug.Print
For intD = 0 To conTest.Documents.Count - 1
Set docTest = conTest.Documents(intD)
Debug.Print " > Document: "; docTest.Name;
Debug.Print " Owner: "; docTest.Owner;
Debug.Print " Container: "; docTest.Container
Debug.Print " UserName: "; docTest.UserName;
Debug.Print " Permissions: "; docTest.Permissions
Debug.Print " DateCreated: "; docTest.DateCreated;
Debug.Print " LastUpdated: "; docTest.LastUpdated
Debug.Print
Next intD
Next intC
EnumerateDocuments = True
End Function
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, wrk As Workspace, ctr As Container
Dim grp As Group
Set wrk = DBEngine.Workspaces(0)
' Return Database object pointing to current database.
Set dbs = CurrentDb
Set ctr = dbs.Containers!Modules
wrk.Groups.Refresh
For Each grp In wrk.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
End Sub