Rollback a transaction : Transaction « Access « VBA / Excel / Access / Word






Rollback a transaction

 

Sub exaCreateAction2()
    Dim ws As Workspace
    Dim db As Database
    Dim qdf As QueryDef
    Dim strSQL As String
    
    Set ws = DBEngine(0)
    Set db = CurrentDb
    
    strSQL = "UPDATE BOOKS SET Price = Price*1.1 WHERE Price > 20"
    
    Set qdf = db.CreateQueryDef("PriceInc", strSQL)
    ws.BeginTrans
    qdf.Execute
    If qdf.RecordsAffected > 15 Then
        Debug.Print qdf.RecordsAffected 
        ws.Rollback
    Else
        Debug.Print qdf.RecordsAffected
        ws.CommitTrans
    End If
End Sub

 








Related examples in the same category

1.Using a Database Transaction to Insert Records
2.Transaction Processing in Access 2007 Using BeginTrans, Logging, CommitTrans, and RollbackTrans
3.Use transaction