PRB: WillChangeRecord Event Does Not Fire on Update

ID: Q189365


The information in this article applies to:
  • ActiveX Data Objects (ADO), versions 2.0, 2.1 SP2


SYMPTOMS

When issuing a Recordset.Update, the WillChangeRecord event does not fire.


CAUSE

Whether this event fires or not depends on the type of cursor opened. If the locking schema for the cursor is adLockBatchOptimistic then this event will not fire on Recordset.Update; instead it fires on UpdateBatch.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Visual Basic Project.


  2. Set a Project Reference to the Microsoft ActiveX Data Objects Library.


  3. Select the default form to open the Code window.


  4. Delete the Form_Load code.


  5. Copy and paste the following into the Code window:


  6. 
       Dim oCn As Connection
       Dim WithEvents oRs As Recordset
       Dim oCm As Command
    
       Private Sub Form_Load()
    
       Set oCn = New Connection
       Set oRs = New Recordset
       Set oCm = New Command
    
       With oCn
          .ConnectionString = "PROVIDER=SQLOLEDB;" & _
                              "DATA SOURCE=matthofa;" & _
                              "Initial Catalog=pubs;" & _
                              "User Id=sa;Password="
          .Open
       End With
    
       With oCm
          Set .ActiveConnection = oCn
          .CommandText = "select * from authors"
          .CommandType = adCmdText
       End With
    
       With oRs
          Set .ActiveConnection = oCn
          .CursorLocation = adUseClient
          .CursorType = adOpenStatic
          .LockType = adLockBatchOptimistic
          .Open oCm
       End With
    
       oRs(1) = "something new"
       oRs.Update
       oRs.UpdateBatch
    
       End Sub
    
       Private Sub oRs_WillChangeRecord _
          (ByVal adReason As ADODB.EventReasonEnum, _
          ByVal cRecords As Long, _
          adStatus As ADODB.EventStatusEnum, _
          ByVal pRecordset As ADODB.Recordset)
    
          MsgBox "oRs_WillChangeRecord"
       End Sub 
  7. Modify the connection string to point to your server.


  8. Step through the program. The WillChangeRecord event is fired on oRs(1) = "something new" and oRs.UpdateBatch, but not on oRS.Update.

Additional query words:

Keywords : kbADO200 kbDatabase kbVBp600 kbGrpVBDB kbGrpMDAC kbDSupport kbMDAC200 kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:2.0,2.1 SP2
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: November 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.