>

CancelUpdate Method

Applies To

Dynaset-Type Recordset Object, Recordset Object, Table-Type Recordset Object.

Description

Cancels any pending updates for the Recordset object represented by the object placeholder.

Syntax

object.CancelUpdate

The object placeholder represents an object expression that evaluates to an object in the Applies To list.

Remarks

The CancelUpdate method cancels any pending updates due to an Edit or AddNew operation. For example, if a user invokes the Edit or AddNew method and hasn't yet invoked the Update method, CancelUpdate cancels any changes made after Edit or AddNew was invoked.

Note

Using the CancelUpdate method has the same effect as moving to another record without using the Update method except that the current record doesn't change, and various properties, such as BOF and EOF, aren't updated.

Use the EditMode property to determine if there is a pending operation that can be canceled.

See Also

AddNew Method; BOF, EOF Properties; EditMode Property.

Example (Microsoft Access)

The following example creates a new record in an Employees table, enters values, and prompts the user to save the changes. If the user chooses not to save the changes, the Update method is canceled.


Sub NewRecord()
    Dim dbs As Database, rst As Recordset

    ' Return Database variable pointing to current database.
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("Employees")
    With rst
        ' Add new record to end of Recordset object.
        .AddNew
        .[LastName] = "Christopher"        ' Add data.
        .[FirstName] = "Kevin"
    End With
    ' Prompt user to save changes.
    If MsgBox("Save these changes?", vbYesNo) = vbNo Then
        ' If user chooses No, cancel changes.
        rst.CancelUpdate
    Else
        ' If user chooses Yes, save changes.
        rst.Update
    End If
    dbs.Close
End Sub