Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: ADO: Compile Error: User-Defined Type Not Defined


Symptoms

When you compile your ADO project, you receive the following error:

Compile error: User-defined type not defined
This can occur on either a Connection or Command object.

↑ Back to the top


Cause

You may have referenced one of the following libraries instead of the Microsoft ActiveX Data Objects (ADODB) type library:

  • Microsoft ActiveX Data Objects Recordset (ADOR) type library.

    -or-
  • Microsoft ActiveX Data Objects (Multi-dimensional) (ADOMD) type library.

↑ Back to the top


Resolution

Remove the incorrect type library reference from your project, and add a reference to the correct type library.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More Information

Steps to Reproduce Behavior

  1. Create a new project and add a command button (Command1) to a form.
  2. Add a reference to the Microsoft ActiveX Data Objects Recordset Library.
  3. Add the following code to the form:
       Private Sub Command1_Click()
    Dim cn As ADODB.Connection
    End Sub
  4. Run the project and click the command button. The error appears.
  5. Remove the reference, and add a reference to the Microsoft ActiveX Data Objects Library.
  6. Click the command button. The error does not appear.
NOTE:

  • Microsoft Access users will have to use ADODB.Connection to avoid confusion with the DAO Connection object.
  • If the Intellitype feature is turned on, you should notice that it does not show Connection as a valid object with the ADOR type library, but does with the ADODB type library. This is a good indication that you do not have the correct type library referenced.
  • This error can also occur when referencing objects in other type libraries that aren't referenced.

↑ Back to the top


Keywords: kb, kbprb, kbdsupport

↑ Back to the top

Article Info
Article ID : 184609
Revision : 5
Created on : 8/19/2020
Published on : 8/20/2020
Exists online : False
Views : 113