Use Transactions in a DAO Recordset in VB

By the way, here's the code:

Dim wrkCurrent As DAO.Workspace
Dim dbsNorthwind As DAO.Database
Dim rstEmployee As DAO.Recordset
On Error GoTo ErrorHandler
Set wrkCurrent = DBEngine.Workspaces(0)
Set dbsNorthwind = CurrentDB
Set rstEmployee = dbsNorthwind.OpenRecordset("Employees")
wrkCurrent.BeginTrans
Do Until rstEmployee.EOF
If rstEmployee!Title = "Sales Representative" Then
rstEmployee.Edit
rstEmloyee!Title = "Sales Associate"
rstEmployee.Update
End If
rstEmployee.MoveNext
Loop
If MsgBox("Save all changes?", vbQuestion + vbYesNo) = vbYes Then
wrkCurrent.CommitTrans
Else
wrkCurrent.Rollback
End If
rstEmployee.Close
dbsNorthwind.Close
wrkCurrent.Close
Set rstEmployee = nothing
Set dbsNorthwind = Nothing
Set wrkCurrent = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
view raw trxdao.vb hosted with ❤ by GitHub

Komentar