CancelUpdate Method
Applies To
Dynamic-Type Recordset object, Dynaset-Type Recordset object, Forward-Only–Type Recordset object, Recordset object, Snapshot-Type Recordset object, Table-Type Recordset object.
Description
Cancels any pending updates for a Recordset object.
Syntax
recordset.CancelUpdate type
The AppendChunk method syntax has these parts.
Part | Description |
|
recordset | An object variable that represents the Recordset object for which you are canceling pending updates. |
type | Optional. A constant indicating the type of update, as specified in Settings (ODBCDirect workspaces only). |
Settings
You can use the following values for the type argument only if batch updating is enabled.
Constant | Description |
|
dbUpdateRegular | Default. Cancels pending changes that aren't cached. |
dbUpdateBatch | Cancels pending changes in the update cache. |
Remarks
You can use the CancelUpdate method to cancel any pending updates resulting from 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.
Check the EditMode property of the Recordset to determine if there is a pending operation that can be canceled.
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.
See Also
AddNew method, BOF, EOF properties, EditMode property, Update method.
Example
This example shows how the CancelUpdate method is used with the AddNew method.
Sub CancelUpdateX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim intCommand As Integer
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = dbsNorthwind.OpenRecordset( _
"Employees", dbOpenDynaset)
With rstEmployees
.AddNew
!FirstName = "Kimberly"
!LastName = "Bowen"
intCommand = MsgBox("Add new record for " & _
!FirstName & " " & !LastName & "?", vbYesNo)
If intCommand = vbYes Then
.Update
MsgBox "Record added."
' Delete new record because this is a
' demonstration.
.Bookmark = .LastModified
.Delete
Else
.CancelUpdate
MsgBox "Record not added."
End If
End With
dbsNorthwind.Close
End Sub
This example shows how the CancelUpdate method is used with the Edit method.
Sub CancelUpdateX2()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Dim strFirst As String
Dim strLast As String
Dim intCommand As Integer
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstEmployees = dbsNorthwind.OpenRecordset( _
"Employees", dbOpenDynaset)
With rstEmployees
strFirst = !FirstName
strLast = !LastName
.Edit
!FirstName = "Cora"
!LastName = "Edmonds"
intCommand = MsgBox("Replace current name with " & _
!FirstName & " " & !LastName & "?", vbYesNo)
If intCommand = vbYes Then
.Update
MsgBox "Record modified."
' Restore data because this is a demonstration.
.Bookmark = .LastModified
.Edit
!FirstName = strFirst
!LastName = strLast
.Update
Else
.CancelUpdate
MsgBox "Record not modified."
End If
.Close
End With
dbsNorthwind.Close
End Sub
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 reference to current database.
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Employees")
With rst
' Add new record to end of Recordset object.
.AddNew
' Add data.
!LastName = "Christopher"
!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
rst.Close
Set dbs = Nothing
End Sub