PRB: WillChangeRecord Event Does Not Fire on Update

ID: Q189365


The information in this article applies to:


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 2.0 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:
    
       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<BR/>
          .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 


Additional query words: kbnokeyword kbado200 kbMDAC200 kbVBp600


Keywords          : kbnokeyword kbADO200 kbVBp600 kbMDAC200 
Version           : WINDOWS:2.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 27, 1999