"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message news:O2L4yPnJGHA.3064[ at ]TK2MSFTNGP10.phx.gbl...
[Quoted Text] > "Douglas J Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message > news:%230ql1zlJGHA.916[ at ]TK2MSFTNGP10.phx.gbl > > I believe you should issue the CommitTrans before you close the > > recordset(s). Certainly, if you need to issue a Rollback, I would > > think it would have to be done before the recordset is closed. > > I've tested it, and that does not appear to be the case. > > '----- start of example code ----- > Sub TestTransaction() > > Dim ws As DAO.Workspace > Dim db As DAO.Database > Dim rs As DAO.Recordset > > Set ws = Application.DBEngine.Workspaces(0) > Set db = ws.Databases(0) > > ws.BeginTrans > > Set rs = db.OpenRecordset("Table1") > > ' Note: Table1 contains these fields: > ' ID (autonumber) > ' Description (text) > ' Modified (date/time) > > rs.AddNew > rs!Description = "Added inside transaction" > rs!Modified = Now() > rs.Update > > rs.Close > Set rs = Nothing > Set db = Nothing > > If MsgBox("Commit?", vbYesNo) = vbYes Then > ws.CommitTrans > Else > ws.Rollback > End If > > End Sub > '----- end of example code -----
That's what I get for being too lazy to test. <g>
Thanks for the correct information, Dirk.
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!)
|