Transaction in Access
I need to execute several sql clauses, inserts, updates and delete for example. How to use a transaction in Acc开发者_JAVA百科ess to bind them together?
DAO is preferred.
like:
BeginTrans
Excute SQL_1
Excute SQL_2
.....
CommitTrans
Thanks!
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
If you use DAO, you can use the BeginTrans and CommitTrans methods of the global DBEngine object:
Dim db As Database
Set db = CurrentDb
DBEngine.BeginTrans
db.Execute SQL_1
db.Execute SQL_2
...
DBEngine.CommitTrans
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论