Setting and Retrieving SummaryInfo Properties
When you select Database Properties from the Manage menu under the Office button, Access opens the Properties dialog box. It displays several built-in properties, some you can change, and some you can't. The General tab displays various information about the database, including its file location and size, creation date, and the dates it was last modified and accessed. The Summary tab enables you to enter your own properties, such as the document Title (which is different from the Application Title, because it's set from the Access Options dialog box), Subject, Author, Manager, and so on. These two tabs contain the information the Search facility uses when you want to find a specific file, using File → Open → Find.
In DAO code, you can set and retrieve the value of any of these properties from the SummaryInfo document of the Databases container for the current database. Of course, you don't have to create these properties before using them. Access creates them automatically when you launch the database. The following code line illustrates how to access the Subject property shown in the Properties dialog box.
dbs.Containers("Databases").Documents("SummaryInfo").Properties("Subject")
Setting and Retrieving User-Defined Properties
You can also create and use user-defined properties for other purposes. A lot of developers often use a custom database property to record the database version. As with the example of a field's Description property, there are two ways to create a user-defined property: using the user interface, and through code.
To create such a property with the user interface, click the Office button and select Manage → Database Properties. The Properties dialog box displays. Select the Custom tab. Enter the property name into the Name box, select the appropriate data type, give it a value, and click Add.
The following example shows how you can create the same property in code, and retrieve its value using Debug.Print:
Public Sub SetVersion(strVersion As String) Dim prop As DAO.Property Dim dbs As DAO.Database On Error Resume Next Set dbs = CurrentDb 'Set the property's value 'If it doesn't exist, an error 3270 "Property not found" will occur dbs.Containers("Databases")("UserDefined").Properties("Version") = _ strVersion If Err <> 0 Then 'If the property doesn't exist, create it Set prop = dbs.CreateProperty("Version", dbText, strVersion) 'Append it to the collection dbs.Containers("Databases")("UserDefined").Properties.Append prop End If 'Now read the property Debug.Print _ dbs.Containers("Databases")("UserDefined").Properties("Version") 'Clean up Set prop = Nothing Set dbs = Nothing End Sub
First you must test that the property exists. In this example, you test it by attempting to set its value. If all goes well, the property must already exist, and its value is set. If an error occurs, you have to create the property - again by using the CreateProperty method at database level, and then appending it to the appropriate collection.
In this tutorial:
- Using DAO to Access Data
- Data Access Objects
- New Features in DAO
- Referring to DAO Objects
- The DBEngine Object
- Using Transactions
- The Errors Collection
- The Databases Collection
- The CurrentDb() Function
- Opening an External Database
- Closing and Destroying Database Object References
- DAO Property Types
- Setting and Retrieving Built-In Object Properties
- Setting and Retrieving SummaryInfo Properties
- Creating Schema Objects with DAO
- Creating Indexes
- Creating Relations
- Creating Multi-Value Lookup Fields
- Database Encryption with DAO
- Setting Encryption Options
- Managing Access (JET) Security with DAO
- Creating Security Objects
- Creating and Deleting Groups
- Managing Passwords
- Data Access with DAO
- Modifying a QueryDef
- Filtering and Ordering Recordsets
- Navigating Recordsets
- BOF, EOF
- Navigating Recordsets with Multi-Value Lookup Fields
- Bookmarks and Recordset Clones
- Finding Records
- Working with Recordsets
- Using Arrays with Recordsets
- Working with Attachment Fields
- Append Only Fields