>

Requery Method

Applies To

Dynaset-Type Recordset Object, Recordset Object, Snapshot-Type Recordset Object.

Description

Updates the data in a Recordset object by re-executing the query on which the object is based.

Syntax

object.Requery [NewQuerydef]

The Requery method syntax has the following parts.

Part Description
 
object The name of an existing table-type Recordset object that has a defined index as specified by the Recordset object's Index property.
NewQuerydef A Querydef object, which is an optional parameter.

Remarks

Use this method to make sure that a Recordset contains the most recent data. This method re-populates the current Recordset by either using the currrent query parameters or the new ones supplied by the NewQuerydef argument.

When you use Requery, all changes made to the data in the underlying table by other users are displayed in the Recordset, and the first record in the Recordset becomes the current record.

You can't use the Requery method on dynaset- or snapshot-type Recordset objects whose Restartable property is set to False, nor can you use it on a table-type Recordset. However, if you supply the optional NewQueryDef argument, the Restartable property is ignored.

If both the BOF and EOF property settings of the Recordset object are True after you use the Requery method, the query didn't return any records and the Recordset will contain no data.

See Also

BOF, EOF Properties; QueryDef Object, Requery Method.

Example

This example determines the Restartable property setting of a dynaset-type Recordset and then uses the Requery method on the Recordset.


Dim dbsNorthwind As Database, rstChangeOften As Recordset
Set dbsNorthwind =  DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
Set rstChangeOften = dbsNorthwind.OpenRecordset _
    ("Table That Changes Often", dbOpenDynaset)
If rstChangeOften.Restartable = True Then
    rstChangeOften.Requery
End If
dbsNorthwind.Close
Example (Microsoft Access)

The following example checks the Restartable property setting of a dynaset-type Recordset object and then uses the Requery method on the Recordset object.


Sub RequerySource()
    Dim dbs As Database, rstOrders As Recordset

    ' Return Database variable that points to current database.
    Set dbs = CurrentDb
    Set rstOrders = dbs.OpenRecordset("Orders", dbOpenDynaset)
    If rstOrders.Restartable = True Then
        rstOrders.Requery
    Else
        rstOrders.Close
    End If
End Sub