Document Object
Description
A Document object includes information about one instance of an object. The object can be a database, saved table, query, or relationship (Microsoft Jet databases only).
Remarks
Each Container object has a Documents collection containing Document objects that describe instances of built-in objects of the type specified by the Container. The following table lists the type of object each Document describes, the name of its Container object, and what type of information Document contains.
Document | Container | Contains information about |
|
Database | Databases | Saved database |
Table or query | Tables | Saved table or query |
Relationship | Relations | Saved relationship |
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.
With a Document object, you can:
- Use the Name property to return the name that a user or the Microsoft Jet database engine gave to the object when it was created.
- Use the Container property to return the name of the Container object that contains the Document object.
- Use the Owner property to set or return the owner of the object. To set the Owner property, you must have write permission for the Document object, and you must set the property to the name of an existing User or Group object.
- Use the UserName or Permissions properties to set or return the access permissions of a user or group for the object. To set these properties, you must have write permission for the Document object, and you must set the UserName property to the name of an existing User or Group object.
- Use the DateCreated and LastUpdated properties to return the date and time when the Document object was created and last modified.
Because a Document object corresponds to an existing object, you can't create new Document objects or delete existing ones. To refer to a Document object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:
Documents(0)
Documents("name")
Documents![name]
Properties
AllPermissions property, Container property, DateCreated, LastUpdated properties, KeepLocal property, Name property, Owner property, Permissions property, Replicable property, UserName property.
Methods
CreateProperty method.
See Also
User object.
Specifics (Microsoft Access)
In addition to the Document objects defined by the Microsoft Jet database engine, the following Document objects are defined by Microsoft Access.
Document | Container | Contains information about |
|
Form | Forms | Saved form |
Macro | Scripts | Saved macro |
Module | Modules | Saved module |
Report | Reports | Saved report |
SummaryInfo | Databases | Database document summary |
UserDefined | Databases | User-defined properties |
The Document objects defined by Microsoft Access are Microsoft Access database objects, not Data Access Objects (DAO). These Document 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 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.
Microsoft Access defines two Document objects in the Databases Container object — SummaryInfo and UserDefined.
The SummaryInfo Document object provides programmatic access to document summary properties — including Title, Subject, Author, Keywords, Comments, Manager, Company, Category, and Hyperlink Base. You can also set these properties on the Summary tab of the Database Properties dialog box, available by clicking Database Properties on the File menu.
To set these properties in Visual Basic, you must create them and append them to the Properties collection of the SummaryInfo Document object if they haven't already been set in the Database Properties dialog box. Once a property has been created, you must explicitly refer to the Properties collection to set it. In the following example, doc is an object variable pointing to the SummaryInfo Document object:
doc.Properties!Title = "Northwind Traders"
For more information on creating and setting Microsoft Access–defined properties, see the Property object and the CreateProperty method.
The UserDefined Document object provides programmatic access to user-defined properties defined on the Custom tab of the Database Properties dialog box. You can also create these properties in Visual Basic and append them to the Properties collection of the UserDefined Document object.
Note Don't confuse properties defined in the Properties collection of a Database document with properties defined in the Properties collection of a Database object. You can create user-defined properties in either Properties collection, but only those defined on the SummaryInfo or UserDefined Document objects can be set from the Database Properties dialog box.
You can use Document objects to establish and enforce permissions for individual Microsoft Access database objects. To set permissions for a Document object, set the UserName property of the Document object to the name of an existing User or Group object. Then set the Permissions property for the Document 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 Documents collection of the Tables container, and then enumerates the Properties collection of the first Document object in the collection.
Sub DocumentX()
Dim dbsNorthwind As Database
Dim docLoop As Document
Dim prpLoop As Property
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
With dbsNorthwind.Containers!Tables
Debug.Print "Documents in " & .Name & " container"
' Enumerate the Documents collection of the Tables
' container.
For Each docLoop In .Documents
Debug.Print " " & docLoop.Name
Next docLoop
With .Documents(0)
' Enumerate the Properties collection of the first.
' Document object of the Tables container.
Debug.Print "Properties of " & .Name & " document"
On Error Resume Next
For Each prpLoop In .Properties
Debug.Print " " & prpLoop.Name & " = " & _
prpLoop
Next prpLoop
On Error GoTo 0
End With
End With
dbsNorthwind.Close
End Sub
Example (Microsoft Access)
The following example prints the name of each Form Document object in the current database and the date it was last modified:
Sub DocumentModified()
Dim dbs As Database, ctr As Container, doc As Document
' Return reference to current database.
Set dbs = CurrentDb
' Return referenct to Forms container.
Set ctr = dbs.Containers!Forms
' Enumerate through Documents collection of Forms container.
For Each doc In ctr.Documents
' Print Document object name and value of LastUpdated property.
Debug.Print doc.Name; " "; doc.LastUpdated
Next doc
Set dbs = Nothing
End Sub