Results 1 to 2 of 2

Thread: More transaction headache

  1. #1

    Thread Starter
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    You would use begintrans and rollback when you are making multiple changes to the database. (multiple EDIT --> UPDATEs)

    When you only need to make a single change, use .EDIT, and use .CANCELUPDATE when you need to cancel changes, or update to commit them.

    Example using DAO:
    Code:
        'declare objects
        Dim db As Database
        Dim rs As Recordset
        
        
        'get db/rs
        Set db = DBEngine.OpenDatabase("Nwind.mdb")
        Set rs = db.OpenRecordset("Select * from Customers")
        
        
        'BEGIN TRANSACTION
        DBEngine.BeginTrans
        
        
        'SHOW YOU THE INITIAL VALUE
        MsgBox rs.Fields(1).Value
        
        
        'ASSIGN NEW NAME TO FIELD
        rs.Edit
        rs.Fields(1).Value = "NewName"
        rs.Update
        
        
        'SHOWS YOU THAT THE UPDATE WAS SUCCESSFUL
        MsgBox rs.Fields(1).Value
        
        
        'CANCEL ALL CHANGES SINCE BEGINTRANS
        'EVEN THOUGH WE UPDATED SUCCESSFULLY
        DBEngine.Rollback
        
        
        'DISPLAY INITIAL VALUE
        'NOTICE THAT IT IS BACK TO
        'WHAT WE STARTED WITH
        MsgBox rs.Fields(1).Value

  2. #2
    New Member
    Join Date
    Jan 2000
    Posts
    2

    Post

    I have program with a structure like this.

    I have workspace defined

    One button called edit

    One button called cancel

    Code of edit-button : Workspace.BeginTrans

    Code of cancel-button : WorkSpace.Rollback


    However when i first press the edit-button and then the cancel-button i get a error-message that there was no begintrans.

    How is this possible ?
    Please help this puzzled boy.

Posting Permissions

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



Click Here to Expand Forum to Full Width