Microsoft KB Archive/191455

= BUG: WillChangeRecordset Event Not Executed =

Article ID: 191455

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 Q191455



SYMPTOMS
When the Close method of an ActiveX Data Objects (ADO) RecordSet object is called, the WillChangeRecordset event does not fire. The documentation for the WillChangeRecordset event states, in error, that this event fires when closing the RecordSet.

The documentation for ADO 2.5 and later states that the WillChangeRecordset event may fire on the Requery and Open operations. At the same time, however, adRsnClose is still listed as a possible reason for the WillChangeRecordset event.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a Standard EXE Project in Visual Basic. From Project menu, choose Components and then select "Microsoft ActiveX Data Objects Library". Add a TextBox control and Command Button to the form.  Add the following code to the General Declarations of the form:

Note You must change UID= and PWD= to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation.on the database. Dim WithEvents rst As ADODB.Recordset Dim cn As New ADODB.Connection

Private Sub Form_Load With cn  .CursorLocation = adUseClient .Open "dsn=pubs;uid= ;pwd= ;" End With

Set rst = cn.Execute("Select * from Authors") Set Text1.DataSource = rst Text1.DataField = "au_lname"

End Sub

Private Sub rst_WillChangeRecordset(ByVal adReason As _    ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, _     ByVal pRecordset As ADODB.Recordset) Debug.Print "ADO WillChangeRecordset"

End Sub

Private Sub Command1_Click Debug.Print "About to Close"

rst.Close

Debug.Print "Close complete" Unload Me

End Sub 

Note The preceding code sample assumes that you have a DSN that points to a valid SQL Server and the Pubs database.
 * Press the F5 key to run the application and then click the Command Button. Notice that in the Debug Window the "ADO WillChangeRecordset" is not printed after "About to Close" prints.

Note It is printed immediately after the Text box's DataField is assigned.

