VB Migration Partner

KNOWLEDGE BASE - Database and data-binding


Previous | Index | Next 

[HOWTO] Solve syntax errors in ADODC event handlers

A little-known fact about ADO is that the Recordset class defined in ADO 2.1 and later versions isn’t perfectly compatible with the Recordset class defined in version 2.0 of the ADODB type library. In most cases this difference doesn’t cause any problem and you can just open the VB6 References dialog box so that the ADO reference now points to a newer version, without having to edit existing code.

In some cases, however, this behavior must be taken into account. More precisely, you should worry about the ADO version being use when your VB6 application handles one of the following events of the ADODC control: EndOfRecordset, FieldChangeComplete, MoveComplete, RecordChangeComplete, RecordsetChangeComplete, WillChangeField, WillChangeRecord, WillChangeRecordset, and WillMove. (All these events have a parameter of type ADODB.Recordset.) Here is an example of such an event handler:

    Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _
            ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, _
            ByVal pRecordset As ADODB.Recordset)
        ' display number of current record and total number of records
        lblRecord.Caption = CStr(Adodc1.Recordset.AbsolutePosition) & _
            " of " & Str(Adodc1.Recordset.RecordCount)
    End Sub

The problem is: the ADODC control provided with the original VB6 release was compiled against ADO 2.0, therefore the handlers for these events receive a reference to the original Recordset 2.0 class. If you have updated the type library reference to point to a more recent version of ADO – or if you have moved the VB6 project on a computer where only more recent versions of ADO are installed – any attempt to compile the VB6 application results in one or more of the following errors:

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

Because you often migrate a VB6 on a computer that is different from the one where the application was originally developed, this error may manifest itself quite often. You can read more information about this problem in the following MSDN Knowledge Base articles:

http://support.microsoft.com/kb/222145
http://support.microsoft.com/kb/193326

There are two ways to work around this problem. First, you can install Visual Basic’s SP6; this Service Pack contains a newer version of the ADODC control, which is compiled against a newer version of ADO.

Second, you can edit the event handler signature and replace the reference to the ADODB.Recordset with a reference to the ADODB.Recordset20 class. Such a class is defined in all ADO type libraries from version 2.1 onward, but you have to use the Show Hidden Members command inside VB6’s object browser to show it. The previous event handler must be edited as follows:

    Private Sub Adodc1_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _
            ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, _
            ByVal pRecordset As ADODB.Recordset20)
        ' display number of current record and total number of records
        lblRecord.Caption = CStr(Adodc1.Recordset.AbsolutePosition) & _
            " of " & Str(Adodc1.Recordset.RecordCount)
    End Sub

VB Migration Partner correctly recognizes the ADODB.Recordset20 name and maps it to the ADODB.Recordset class defined in the ADODB primary interop assembly.

In one case you might need to perform an additional manual fix. If the original VB6 application has a reference to the ADO 2.0 type library, the migrated VB.NET application might not be able to compile the event handler definition. If this is the case, simply drop and then re-add the reference to the ADODB primary interop assembly. After this operation the converted VB.NET code compiles correctly and works as expected.

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.




Code Architects and its partners offers remote and onsite migration services.

More details




Subscribe to our free newsletter for useful VB6 migration tips and techniques.

newsletter



To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice



A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial




The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote




Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers