cn.BeginTrans
tmpS = "update WLYE set WLYE_NCJF=1000 where WLYE_WLBH='0003'"
cn.Execute tmpS
' 询问用户是否想提交以上所做的全部更改。
If MsgBox("是否提交所做的更改?", vbYesNo) = vbYes Then
cn.CommitTrans
Else
cn.RollbackTrans
End If
cn.Close
Set cn = Nothing
dao的-------------------
Sub BeginTransX()
Dim strName As String
Dim strMessage As String
Dim wrkDefault As Workspace
Dim dbsNorthwind As Database
Dim rstEmployees As Recordset
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsNorthwind = OpenDatabase("Northwind.mdb")//打开库
Set rstEmployees = dbsNorthwind.OpenRecordset("Employees")//打开对应的表
wrkDefault.BeginTrans//开始事物
With rstEmployees
Do Until .EOF
If !Title = "Sales Representative" Then
strName = !LastName & ", " & !FirstName
strMessage = "Employee: " & strName & vbCr & _
"Change title to Account Executive?"
If MsgBox(strMessage, vbYesNo) = vbYes Then
.Edit
!Title = "Account Executive"
.Update
End If
End If
.MoveNext
Loop
If MsgBox("Save all changes?", vbYesNo) = vbYes Then
wrkDefault.CommitTrans//提交事物
Else
wrkDefault.Rollback//回滚事物
End If