Question : Roll Back In Ms Access ?

Hi there ,

I am developing an Accounting system using VB/Ms Acces. I want to know that is there any thing like RollBack in Ms Access Database which I can use in case some error occures and I use it to Roll back my Half incomplete Transactions.

Answer : Roll Back In Ms Access ?

It will do what you want.

It will rollback everything between BeginTrans and CommiTrans.

Here is a link for the ado transaction explanation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdamth01_4.asp

I an example for dao:

Sub TransferFunds ()
Dim MyWS As Workspace, MyDB As Database, MyQuery As QueryDef

On Error GoTo TransferFailed

Set MyWS = DBEngine.Workspaces(0)
Set MyDB = MyWS.OpenDatabase("somedb.mdb")
MyWS.BeginTrans                ' Begin transaction.
' Create temporary pass-through query.
Set MyQuery = MyDB.CreateQueryDef("")
MyQuery.Connect = "ODBC;DSN=Bank;UID=teller;DATABASE=access"
MyQuery.ReturnsRecords = False
MyQuery.SQL = "UPDATE Accounts SET Balance = Balance - 100
 _WHERE AccountID = 'SMITH_SAV'"
MyQuery.Execute                ' Subtract from savings account.
MyQuery.SQL = "UPDATE Accounts SET Balance = Balance + 100
 _WHERE AccountID = 'SMITH_CHK'"
MyQuery.Execute                ' Add to checking account.
MyQuery.SQL = "INSERT INTO LogBook (Type, Source, Destination,
 _Amount) VALUES ('Transfer', 'SMITH_SAV', 'SMITH_CHK', 100)"
MyQuery.Execute                ' Log transaction.
MyWS.CommitTrans                  ' Commit transaction.
MyDB.Close
Exit Sub

TransferFailed:
    MsgBox Error$
    MyWS.Rollback        ' If one operation fails, roll them all back.
    Exit Sub
End Sub


Chris
Random Solutions  
 
programming4us programming4us