• BeginTrans (Win XP Office 2003)

    Author
    Topic
    #455913

    I am starting to use the Begin/Commit in some code. In the attached sample code which I was studying, I have some doubts.

    Would you normally put the Rollback instruction in the error routine? I assume it is in the If statement for example purposes.

    What happens if the error routine closes the procedure and neither a CommitTrans nor a Rollback command have been issued?

    Thanks.

    Viewing 0 reply threads
    Author
    Replies
    • #1137345

      You should put a line

      wks.Rollback

      in the error handling section below the line

      cmdBeginTrans_ClickError:

      If you don’t want to ask the user whether the changes should be saved, you can replace

      ‘Ask if the user wants to commit to all the changes
      ‘made above.
      If MsgBox(“Save all changes?”, vbYesNo) = VbYes Then
      wks.CommitTrans
      Else
      wks.Rollback
      End If

      with the single line

      wks.CommitTrans

      • #1137376

        Thank you. Just one more point, please.

        What happens if the error routine closes the procedure and neither a CommitTrans nor a Rollback command have been issued?

        • #1137381

          The error handling section issues a rollback, so unless your procedure completely crashes Access before a commit or rollback, the transaction will have been either committed or rolled back when you exit the procedure, even if an error occurred.

    Viewing 0 reply threads
    Reply To: BeginTrans (Win XP Office 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: