Share via


The CurrentData and CurrentProject Objects

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In previous versions of Microsoft® Access, you can use Data Access Objects (DAO's) and their methods and properties to get information about forms, reports, macros, tables, fields, relationships, and queries. For example, you can use Document objects to get information about the tables and queries in a database. There are separate Container objects representing forms, reports, scripts (Access macros), tables (tables and queries), and modules. Each of these Container objects contains a collection of Document objects representing all the objects of the specified type in the current database. Each Document object contains only summary information about each object and does not provide access to the properties of the object or the data it contains. You use DAO Recordset objects to work with the data in a table or query, and you use members of the Forms or Reports collection to work with forms and reports themselves.

However, in Access, DAO is no longer the default programmatic way to interact with data and objects that contain data; therefore, Access has two new objects — CurrentData and CurrentProject — that contain collections of AccessObject objects, which are used in place of the Container and Document objects available through DAO in previous versions.

Access uses the CurrentData object to store collections of AccessObject objects that are administered by the database engine, for example, tables and queries in .mdb-type databases, and database diagrams, stored procedures, tables, and views in .adp-type databases. Information about each collection of objects is stored in a collection where each object is represented as an AccessObject object. For example, information about tables is contained in the AllTables collection, and information about views is stored in the AllViews collection. To access the CurrentData object, you use the CurrentData property of the Application object. When code is running in an add-in or library database, you would use the CodeData object to refer to the objects managed by the add-in or library database. The CodeData property of the Application object returns the CodeData object.

Note   AccessObject objects contain information about the objects that contain data, but do not provide access to the data itself.

You use the CurrentProject property of the Application object to get information about the Access objects in a database, such as data access pages, forms, macros, modules, and reports. The CurrentProject property of the Application object returns the CurrentProject object, which contains collections of AccessObject objects as well as information about the name, path, and connection of the database itself. For example, the AllForms collection contains information about all the forms in a database, and the AllReports collection contains information about all the reports in the database. When code is running in an add-in or library database, the CodeProject object contains the collections of AccessObject objects in the add-in or library database. The CodeProject property of the Application object returns the CodeProject object.

An AccessObject object exposes the following properties you can use to get information about an object: IsLoaded, Name, Parent, Properties, and Type. These properties are described in the following table.

AccessObject property Description
IsLoaded A Boolean value indicating whether the object is currently loaded. This property is True when an object is open in any view.
Name A String value representing the name of the object.
Parent Returns the parent object for the specified object. For example, the parent of an item in the AllForms collection is the AllForms collection object. The parent of the CurrentProject object is the Application object.
Properties Returns an AccessObjectProperties collection, which contains all the custom properties associated with a particular AccessObject object. The Properties collection can store String or Long Integer values only.
Type A Long Integer value representing one of the objects specified by the acObjectType intrinsic constants.

Note   Collections of AccessObject items are indexed beginning with a value of 0 for the first item in the collection, 1 for the second item, and so on.

The following sample shows how you can use the IsLoaded property to determine if a form, report, or data access page is currently loaded:

With CurrentProject
   Select Case intObjectType
      Case acForm
         IsObjectOpen = .AllForms(strObjName).IsLoaded
      Case acReport
         IsObjectOpen = .AllReports(strObjName).IsLoaded
      Case acDataAccessPage
         IsObjectOpen = .AllDataAccessPages(strObjName).IsLoaded
      Case Else
         Err.Raise ERR_INVALIDOBJTYPE
   End Select
End With

The intObjectType variable would be passed to a procedure as an argument of type acObjectType.

The next sample illustrates how to add custom properties to a form:

Sub AddCustomFormProperty(strFormName As String, _
                         strPropName As String, _
                         varPropValue As Variant)
   ' This procedure illustrates how to add custom
   ' properties to the Properties collection that
   ' is associated with an AccessObject object.
   
   With CurrentProject.AllForms(strFormName).Properties
      .Add strPropName, varPropValue
   End With
End Sub

See Also

Built-in Access Functions and Methods | Creating, Opening, and Closing an Access Application | Working with the Screen Object | Working with the DoCmd Object | Working with the Modules Collection | Working with the References Collection