Microsoft KB Archive/193326

From BetaArchive Wiki

Article ID: 193326

Article Last Modified on 3/14/2005



APPLIES TO

  • Microsoft Visual Basic 6.0 Learning Edition
  • 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.1
  • 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 Q193326

SYMPTOMS

When you run an application that is created using the Visual Basic Application Wizard, you receive the following error message:

Compile error: User-defined type not defined

CAUSE

The Application Wizard allows for the creation of forms via the Data Form Wizard. When a form is created in this manner, a reference to ADO is not added to the project.

RESOLUTION

Add a reference to ADO by selecting References from the Project menu and checking the box next to "Microsoft ActiveX Data Objects Library."

This problem can also be avoided by running through the Application Wizard without adding any data forms, then adding data forms by invoking the Data Form Wizard directly from the Add-Ins menu.

In versions of Visual Basic 6 prior to Service Pack 4, the ADO Data Control's events were designed to work only with ADO version 2.0. After you set a Reference to ADO later than 2.0 to workaround the Application Wizard problem, you receive the following error message

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

To work around this new compile error, you must change the declaration of the ADO Data Control's events to include ADODB.Recordset20 instead of ADODB.Recordset.

Specifically, change the following event procedure:

Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
                

-to-

Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset20)
                

And change:

Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
                

-to-

Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset20)
                

When you use Visual Basic 6 Service Pack 4, the ADO Data Control's events work with ADO versions 2.1 and later. It is not necessary to change the pRecordset arguments to ADODB.Recordset20.

STATUS

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

MORE INFORMATION

Steps to Reproduce Behavior

  1. Select New Project from the File menu.
  2. In the New Project dialog box, select Visual Basic Application Wizard and click OK.
  3. Click Next on each page of the Wizard until you reach the page titled "Data Access Forms."
  4. Click Create New Form.

The following instructions refer to the Data Form Wizard, which is invoked at step 4.

  1. Click Next.
  2. Select a database type and click Next.
  3. Enter the requested connection information and click Next.
  4. Select "Grid (Datasheet)" as the Form Layout, select ADO Data Control as the Binding Type, and then click Next.
  5. Select a Record Source and at least one field, and then click Next.
  6. Click Finish, and click No when prompted to create another form.
  7. Click Finish.
  8. Attempt to run the created project. The result is:

    Compile error: User-defined type not defined.

    The workaround is as specified in the "Resolution" section earlier.


REFERENCES

For additional information Compile error: Procedure declaration does not match description of event or procedure having the same name, click the article number below to view the article in the Microsoft Knowledge Base:

222145 PRB: ADO Data Control Events May Generate a Compilation Error


Keywords: kberrmsg kbbug kbappwizard kbdatabase kbwizard kbctrl KB193326