-
You would use begintrans and rollback when you are making multiple changes to the database. (multiple EDIT --> UPDATEs)
When you only need to make a single change, use .EDIT, and use .CANCELUPDATE when you need to cancel changes, or update to commit them.
Example using DAO:
Code:
'declare objects
Dim db As Database
Dim rs As Recordset
'get db/rs
Set db = DBEngine.OpenDatabase("Nwind.mdb")
Set rs = db.OpenRecordset("Select * from Customers")
'BEGIN TRANSACTION
DBEngine.BeginTrans
'SHOW YOU THE INITIAL VALUE
MsgBox rs.Fields(1).Value
'ASSIGN NEW NAME TO FIELD
rs.Edit
rs.Fields(1).Value = "NewName"
rs.Update
'SHOWS YOU THAT THE UPDATE WAS SUCCESSFUL
MsgBox rs.Fields(1).Value
'CANCEL ALL CHANGES SINCE BEGINTRANS
'EVEN THOUGH WE UPDATED SUCCESSFULLY
DBEngine.Rollback
'DISPLAY INITIAL VALUE
'NOTICE THAT IT IS BACK TO
'WHAT WE STARTED WITH
MsgBox rs.Fields(1).Value
-
I have program with a structure like this.
I have workspace defined
One button called edit
One button called cancel
Code of edit-button : Workspace.BeginTrans
Code of cancel-button : WorkSpace.Rollback
However when i first press the edit-button and then the cancel-button i get a error-message that there was no begintrans.
How is this possible ?
Please help this puzzled boy.