Microsoft KB Archive/189365

= PRB: WillChangeRecord Event Does Not Fire on Update =

Article ID: 189365

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q189365



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.



Steps to Reproduce Behavior
 Create a new Visual Basic Project. Set a Project Reference to the Microsoft ActiveX Data Objects Library. Select the default form to open the Code window. Delete the Form_Load code.  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=servername;" & _ "Initial Catalog=pubs;" & _ "User Id=username;Password=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  Modify the connection string to point to your server.'''Step through the program. The WillChangeRecord event is fired on oRs(1) = "something new" and oRs.UpdateBatch, but not on oRS.Update.'''</li></ol>

Keywords: kbdatabase kbprb KB189365

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.