Export (0) Print
Expand All

AllQueries Collection

The AllQueries collection contains an AccessObject for each query in the CurrentData or CodeData object.

The CurrentData or CodeData object has an AllQueries collection containing AccessObject objects that describe instances of all queries specified by CurrentData or CodeData. For example, you can enumerate the AllQueries collection in Visual Basic to set or return the values of properties of individual AccessObject objects in the collection.

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

The AllQueries collection is indexed beginning with zero. If you refer to a query by its index, the first query is AllQueries(0), the second query is AllQueries(1), and so on.

Note Note
  • The AllQueries collection only contains AccessObject objects within a Microsoft Access database. A Microsoft Access project (.adp) does not contain any macros, see the AllViews collection.

  • To list all open queries in the database, use the IsLoaded property of each AccessObject object in the AllQueries collection. You can then use the Name property of each individual AccessObject object to return the name of a query

  • You can't add or delete an AccessObject object from the AllQueries collection.

The following example prints the name of each open AccessObject object in the AllQueries collection.

Sub AllQueries() 
    Dim obj As AccessObject, dbs As Object 
    Set dbs = Application.CurrentData 
    ' Search for open AccessObject objects in AllQueries collection. 
    For Each obj In dbs.AllQueries 
        If obj.IsLoaded = True Then 
            ' Print name of obj. 
            Debug.Print obj.Name 
        End If 
    Next obj 
End Sub
Show:
© 2014 Microsoft