Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for DAO CommitTrans example...

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Please if anybody has an example of the transaction using DAO, share it with me.

I am copying two huge tables and want to be able to rollback the Delete or Insert statements in case something happens during the process of Inserting or Deleting.

Please help

Thanks
 
Below is an example using DAO. Check On-line Help (BeginTrans), there are several examples:
Code:
Function abc()

    Dim wsp As DAO.Workspace
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

    On error goto ErrHandler

    Set wsp = DBEngine.Workspaces(0)   ' Get default Workspace.
    Set dbs = CurrentDB
	' Open table.
    Set rst = dbs.OpenRecordset("Employees", dbOpenTable)

    wsp.BeginTrans	' Start of transaction.
    rst.MoveFirst
    Do Until rst.EOF
        'do something here
    Loop

    If MsgBox("Save all changes?", vbQuestion + vbYesNo, _
		" Save Changes") = YES Then
        wsp.CommitTrans	' Commit changes.
    Else
        wsp.Rollback	' Undo changes.
    End If

ExitProcedure:

    Exit Function

ErrHandler:

    MsgBox err.description
    if (bolBeginTrans) then
       wsp.Rollback
       bolBeginTrans = false
    End if

    Resume ExitProcedure
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top