Microsoft KB Archive/257714

= FIX: ADO DataControl and DataEnvironment Events Only Work with ADO 2.0 =

Article ID: 257714

Article Last Modified on 8/7/2007

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.01
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 1
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.5 Service Pack 2
 * Microsoft ActiveX Data Objects 2.7

-



This article was previously published under Q257714



SYMPTOMS
When you attempt to use the events of an ADO Data Control or the DataEnvironment with a reference to a version of the Microsoft ActiveX Data Objects (ADO) later than version 2.0, you receive the following error message:

Compile error:

Procedure declaration does not match description of event or procedure having the same name.



CAUSE
The ADO Data Control and the Data Environment were compiled using Microsoft Data Access Components version 2.0.



RESOLUTION
This problem no longer occurs with the ADO Data Control and the Data Environment that ship with Microsoft Visual Studio Service Pack 4 and later.

However, you must now use a reference to the Microsoft ActiveX Data Objects 2.5 Library or later if you are using ADO Data Control and Data Environment events. The ADO Data Control and the Data Environment have been recompiled using Microsoft Data Access Components 2.5. That is, you now see the preceding error message when using the ADO Data Control or the Data Environment with a reference to a version of Microsoft Data Access Components prior 2.5.

In short, when using the events of the ADO Data Control or the Data Environment in Microsoft Visual Basic 6.0 Service Pack 4, be sure to do the following:
 * 1) From the Project menu, clink to select References.
 * 2) From the list of available References, deselect references to Microsoft ActiveX Data Objects prior to version 2.5.
 * 3) From the list of available References, select Microsoft ActiveX Data Objects 2.5 or later.

For versions of Visual Studio prior to service pack 4, the workaround is to add "20" to the ADODB.Recordset Parameter declaration, as described in the articles listed in the "References" section of this article. IMPORTANT: The workaround as described in Q222145 does not work with Visual Studio 6.0 Service Pack 4. The code needs to be changed to use the original declarations for each of the events (20 needs to be removed from the Recordset Parameter declaration).



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in the latest service pack for Visual Studio 6.0.

For additional information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

To download the latest Visual Studio service pack, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/vstudio/Aa718353.aspx



Steps to Reproduce Behavior Using ADO Data Control
This sample uses an ODBC Datasource named Nwind that connects to the Nwind database that comes with Visual Studio.  In Visual Basic, create a new Standard EXE project. Project1 is created by default. Form1 is added by default. From the Project menu, click to select Components. From the list of available Components, select Microsoft ADO Data Control (OLEDB). Place an ADO Data Control and a TextBox onto Form1. ADODC1 and Text1 are created by default. Set the following properties of ADODC1:  ConnectionString: DSN=NWind</li> RecordSource: Select * from Employees</li></ul> </li> Set the following properties of Text1: <ul> DataSource: ADODC1</li> DataField: FirstName</li></ul> </li> From the Project menu, click to select References. From the list of References, deselect Microsoft ActiveX Data Objects 2.0 Library. From the list of available References, click to select Microsoft ActiveX Data Objects 2.1 Library or later.</li>  Paste the following code into Form1's code window: Private Sub Adodc1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset) MsgBox "Hello" End Sub </li> Run the program and note that you see the error message from the "Symptoms" section in the WillMove event.</li></ol>

Steps to Reproduce Behavior, Using DataEnvironment
This sample uses an ODBC Datasource named Nwind that connects to the Nwind database that comes with Visual Studio. <ol> In Visual Basic, create a new Standard EXE project. Project1 is created by default. Form1 is added by default.</li> From the Project menu, click to select Add Data Environment. DataEnvironment1 is added by default. The DataLink Properties window is opened by default. <ol style="list-style-type: lower-alpha;"> On the Provider tab, select Microsoft OLE DB Provider for ODBC Drivers. Click Next.</li> On the Connection tab, select Use data source name. From the list of available ODBC data source names, select Nwind. Click Test Connection. Click OK, and then click OK again.</li></ol> </li> In the DataEnvironment1 (DataEnvironment) window, right-click on Connection1. From the pop-up menu, select Add Command. <ol style="list-style-type: lower-alpha;"> Change the Database Object from Stored Procedure to Table.</li> From the Object Name list, select Customers.</li> Click OK. Command1 is created by default.</li></ol> </li> Drag Command1's icon from the DataEnvironment window onto Form1 and release. Note that Labels and Textboxes representing the fields of the Command object are placed on the form. You do not need to further modify the placement or properties of the Labels and Textboxes.</li> <li>From the Project menu, click to select References. From the list of References, deselect Microsoft ActiveX Data Objects 2.0 Library. From the list of available References, click to select Microsoft ActiveX Data Objects 2.1 Library or later.</li> <li> In the DataEnvironment window, double-click on DataEnvironment1 to open its Code window. Paste the following code into DataEnvironment1's Code window: Private Sub rsCommand1_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset) MsgBox "Hello" End Sub </li> <li>Run the project, and note that the error message in the "Symptoms" section appear in the WillMove event.</li></ol>

<div class="references_section">