DataAccessPages Collection

Microsoft Access Visual Basic

Show All Show All

DataAccessPages Collection

Application DataAccessPages
DataAccessPage
WebOptions

The DataAccessPages collection contains all of the data access pages that are currently open in a Microsoft Access project (.adp) or Access database (.mdb).

Using the DataAccessPages Collection

Use the DataAccessPages collection in Visual Basic or in an expression to refer to data access pages that are currently open. For example, you can enumerate the DataAccessPages collection to set or return the values of properties of individual data access pages in the collection.

ShowTip

The For Each...Next statement is useful for enumerating a collection.

You can refer to an individual DataAccessPage object in the DataAccessPages collection either by referring to the data access page by name, or by referring to its index within the collection. If you want to refer to a specific data access page in the DataAccessPages collection, it's better to refer to the data access page by name because a data access page's collection index may change.

The DataAccessPages collection is indexed beginning with zero. If you refer to a data access page by its index, the first data access page opened is DataAccessPages(0), the second form opened is DataAccessPages(1), and so on. If you opened Page1 and then opened Page2, Page2 would be referenced in the DataAccessPages collection by its index as DataAccessPages(1). If you then closed Page1, Page2 would be referenced in the DataAccessPages collection by its index as DataAccessPages(0).

Note  To list all data access pages in the database, whether open or closed, enumerate the AllDataAccessPages collection of the CurrentProject object. You can then use the Name property of each individual AccessObject object to return the name of a data access page.

You can't add or delete a DataAccessPage object from the DataAccessPages collection.

The following example creates a new data access page and sets certain properties:

Sub NewDataAccessPage()
    Dim dap As AccessObject
    ' Create new data access page.
    Set dap = CreateDataAccessPage("c:\My Documents\Sales Entry", _
            True)
    ' Set data access page Tag property.
    dap.Tag = "Sales Entry Data Access Page"
    ' Restore data access page.
    DoCmd.Restore
End Sub
		

The next example enumerates the DataAccessPages collection and prints the name of each data access page in the DataAccessPages collection.

Sub AllOpenDataAccessPages()
    Dim dap As AccessObject

    Set dbs = Application.CurrentProject
    ' Search for open objects in DataAccessPages collection.
    For Each dap In dbs.AllDataAccessPages
        If dap.IsLoaded = TRUE then
            ' Print name of form.
            Debug.Print dap.Name
        End If
    Next dap
End Sub