Recordset2.CancelUpdate 方法 (DAO)
适用于:Access 2013、Office 2013
取消 Recordset 对象的任意待定更新。
语法
表达式 。CancelUpdate (UpdateType)
表达 一个代表 Recordset2 对象的变量。
参数
名称 |
必需/可选 |
数据类型 |
说明 |
---|---|---|---|
UpdateType |
可选 |
Long |
设置为 UpdateTypeEnum 值之一。 注意:仅当启用了批量更新时, dbUpdateRegular 和 dbUpdateBatch 值才有效。 |
备注
可以使用 CancelUpdate 方法取消执行 Edit 或 AddNew 操作后得到的任何待定更新。 例如,如果用户调用了 Edit 或 AddNew 方法,但尚未调用 Update 方法, CancelUpdate 将取消 Edit 或 AddNew 被调用之后所做的任何更改。
检查 Recordset 的 EditMode 属性以确定是否有可取消的挂起操作。
示例
以下示例演示如何将 CancelUpdate 方法与 AddNew 方法一起使用。
Sub CancelUpdateX()
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset2
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
以下示例演示如何将 CancelUpdate 方法与 Edit 方法一起使用。
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