Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    BeginTrans (Win XP Office 2003)

    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.
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: BeginTrans (Win XP Office 2003)

    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

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Location
    Guatemala City
    Posts
    515
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: BeginTrans (Win XP Office 2003)

    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?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: BeginTrans (Win XP Office 2003)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •