USING CUSTOM DATABASE PROPERTIES

In Access 2000, you can create user-defined database properties from the user interface (UI) as well as through code by using Data Access Objects. Custom database properties can be useful for keeping track of information about the application, such as system paths, version numbers, and other data that the following sections cover.

Creating Database Properties Through the User Interface

You create user-defined properties through the UI by using the Database Properties dialog. To access this dialog, follow these steps:

1.
With the database open, choose Database Properties from the File menu.

2.
Select the Custom tab on the Database Properties dialog. The properties will initially be blank.

3.
Type the name of the property to create in the Name text box.

4.
Select a data type for the property from the Type combo box.

5.
Enter the Value to place in the property.

6.
Click Add.

Figure 26.2 shows the properties used in the World Wide Video Application front end.

Figure 26.2. The Database Properties dialog lets you update the custom properties for VideoApp.mdb.


Accessing Custom Database Properties from VBA

Actually retrieving the database properties from code can be confusing. This is why it's good to create a routine to get the properties and pass only a couple of variables to the routine performing the task. In this case, ap_GetDatabaseProp() is called. The variables passed are dbLocal and the literal strings that are names of the particular properties to be read—BackEndName and LastBackEndPath. Figure 26.2 shows these properties, with the code for the first section as follows:

pstrAppPath = CurrentProject.Path
pstrBackEndName = ap_GetDatabaseProp(dbLocal, "BackEndName")
pstrBackEndPath = ap_GetDatabaseProp(dbLocal, "LastBackEndPath")

Listing 26.2 shows the code for the ap_GetDatabaseProp() function, also found in the modGlobalUtilities module.

Listing 26.2. VideoApp.mdb: Retrieving the Value of the Requested Custom Property
Function ap_GetDatabaseProp(dbDatabase As Database, _
                  strPropertyName As String) As Variant

   ap_GetDatabaseProp = dbDatabase.Containers!Databases _
         .Documents("UserDefined").Properties(strPropertyName).Value

End Function

As you can see, the code for accessing a user-defined database property, although not consisting of many lines, can be confusing. For complete information about accessing the Containers and Documents collections and the proper syntax, review Chapter 4, “Looking at the Access Collections.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.130.201