Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction in Access

Tags:

vba

dao

ms-access

I need to execute several sql clauses, inserts, updates and delete for example. How to use a transaction in Access to bind them together?

DAO is preferred.

like:

BeginTrans
Excute SQL_1
Excute SQL_2
.....
CommitTrans

Thanks!

like image 552
darkjh Avatar asked May 10 '11 11:05

darkjh


1 Answers

Here is a more complete skeleton...

Dim ws As DAO.Workspace
Dim in_trans As Boolean

Sub Transaction()
On Error GoTo Trans_Error
    Set ws = DBEngine.Workspaces(0)
    in_trans=True
    ws.BeginTrans

    <do some SQL stuff; maybe use Err.Raise>

    ws.CommitTrans
    in_trans=False
Trans_Exit:
    Set ws = Nothing
    Exit Sub
Trans_Error:
    If in_trans = True Then
         ws.Rollback
    EndIf
    Resume Trans_Exit
End Sub
like image 58
TonBill Avatar answered Sep 24 '22 01:09

TonBill