PRB: Rollback Causes DAO Recordset Editmode To Be Set Back to 0

Last reviewed: January 21, 1998
Article ID: Q179616
The information in this article applies to:
  • Microsoft Visual Basic Enterprise Edition for Windows, version 5.0

SYMPTOMS

If the edit command is issued for a recordset, and an unrelated transaction is rolled back before the update command, the following error is returned when the update command is issued:

   run-time Error 3020 -- "Update or CancelUpdate Without Addnew or Edit"

If the transaction is committed, this error does not occur.

RESOLUTION

To work around this problem, move the rs.Update method statement so that it is executed before the transaction is started, as shown in the MORE INFORMATION section below. To implement this workaround, change the code that has two update commands, one of which is commented. Uncomment that one and comment the one that is not commented.

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Standard Exe VB project. Form1 is created by default.

  2. Check the reference to the DAO 3.5 object library.

  3. Add a new form, and then add a CommandButton to the form.

  4. Paste the code below into the CommandButton Click event.

  5. Change the OpenDatabase method so that it points to the Northwinds database on your local machine, and then run the project:

          Private Sub Command1_Click()
    

           Dim rs As Recordset
           Dim db As Database
    

           Set db = OpenDatabase("c:\mikework\dbs\nwind.mdb", 0, False, "")
    

           Set rs = db.OpenRecordset("SELECT ContactName FROM Customers", _
           dbOpenDynaset, 0, dbPessimistic)
    
           rs.Edit     'This sets the editmode to 1.
           rs!ContactName = rs!ContactName & "H"
           Debug.Print rs.EditMode  'This will be 1.
           'rs.Update   'Uncomment this line for workaround.
       
           'Start the transaction.
           BeginTrans
              'The processing that occurs in this transaction is unrelated
              'to the above recordset.
           Rollback
       
           Debug.Print rs.EditMode  'Editmode is now 0.
           rs.Update  '<<Error will occur on this line.
       
           rs.Close
           db.Close
       
          End Sub
    
Keywords          : vb5all
Component         : dao
Version           : WINDOWS:5.0
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 21, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.