>

Refresh Method

Applies To

Databases Collection, Documents Collection, Errors Collection, Fields Collection, Groups Collection, Indexes Collection, Parameters Collection, Properties Collection, QueryDefs Collection, Recordsets Collection, Relations Collection, TableDefs Collection, Users Collection, Workspaces Collection.

Description

Updates the objects in a collection to reflect the current database's schema.

Syntax

collection.Refresh

Remarks

The Refresh method can't be used with collections that aren't persistent, such as Databases, Recordsets, or Workspaces.

Note

To determine the position that the Microsoft Jet database engine uses for Field objects in the Fields collection of a QueryDef, Recordset, or TableDef object, use the OrdinalPosition property of each Field object. The Refresh method may change the order of objects within the Fields collection, if the OrdinalPosition property of a Field object in the collection has been changed.

Use the Refresh method in multiuser environments in which other users may change the database. You may also need to use it on any collections that are indirectly affected by changes to the database. For example, if you change a Users collection, you may need to refresh a Groups collection before using the Groups collection.

Tip

A collection is filled with objects the first time it's referred to and won't automatically reflect subsequent changes made to it by other users. If it's likely that a collection has been changed by another user, use the Refresh method on the collection immediately before carrying out any task in your application that assumes the presence or absence of a particular object in the collection. This will ensure that the collection is as up-to-date as possible.

See Also

Append Method, Close Method, Delete Method, OrdinalPosition Property, Requery Method.

Example

This example refreshes the Tables collection in a database in a multiuser environment in case another user has made changes.


Dim wspDefault As Workspace, dbsNorthwind As Database
' Get default workspace.
Set wspDefault = DBEngine.Workspaces(0)
' Open database.
Set dbsNorthwind = wspDefault.OpenDatabase("Northwind.mdb")
...


' Refresh possibly changed collection.
dbsNorthwind.Containers("Tables").Documents.Refresh
Example (Microsoft Access)

The following example refreshes the Indexes collection of a TableDef object. In a database in a multiuser environment, you can use the Refresh method to show changes made by other users.


Sub RefreshIndex()
    Dim dbs As Database, tdf As TableDef
    Dim idx As Index, fld As Field
    
    ' Return Database variable pointing to current database.
    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs!Employees
    tdf.Indexes.Refresh
    For Each idx In tdf.Indexes
        Debug.Print idx.Name; ":"
        For Each fld In idx.Fields
            Debug.Print "   "; fld.Name
        Next fld
    Next idx
End Sub