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.

You receive a "Type mismatch" error when you run the OpenRecordset method


Symptoms

If you dimension an object as a Recordset and then set that object to databaseobject.OpenRecordset(source), you may receive the following error message:
Run time error '13': Type mismatch

↑ Back to the top


Cause

If your project contains references to both the Data Access Objects (DAO) library and the ActiveX Data Objects (ADO) library, you may see multiple Recordset entries in the list when you dimension the Recordset object. This error occurs when you list the ADO library with a higher priority than the DAO library in the References dialog box, regardless of which Recordset entry you select from the list.

↑ Back to the top


Resolution

If you need only the DAO Recordset object, make sure that the reference for the DAO object library has a higher priority in the References dialog box, or clear the reference to Microsoft ActiveX Data Objects.


If you must reference and use both DAO and ADO Recordset objects, dimension the objects explicitly as follows:
   Dim adoRS As ADODB.Recordset
Dim daoRS As DAO.Recordset

↑ Back to the top


More Information

Steps to reproduce the behavior

  1. Start Visual Studio. The New Project dialog box appears.
  2. Click Open. The Form1 form appears.
  3. Right-click the Form1 form, and then click View Code. The Project1 - Form1 (Code) window appears.
  4. Paste the following code in the Project1 code page:
    Dim dbs AS Database
    Dim rs AS Recordset ' When you press the spacebar after "AS," the
    ' list box includes multiple Recordset entries.
    ' Pick any Recordset item, or type "Recordset."
    Private Sub Form_Load()
    Set dbs=OpenDatabase(dbname)
    Set rs=dbs.OpenRecordset(source) ' The error occurs when this line
    ' of code executes.
    End Sub
  5. On the Project menu, click References. The References - Project1 dialog box appears.
  6. Click Microsoft DAO 3.x Object Library, click Microsoft ActiveX Data Objects 2.x Library, and then click OK.

    Note Make sure that the ADO library has the higher priority in the References dialog box list above the DAO library.
  7. On the Run menu, click Start to run the program. You may receive the error message that is mentioned in the "Symptoms" section.

↑ Back to the top


Keywords: kbbillprodsweep, kbdsupport, kbprb, kb

↑ Back to the top

Article Info
Article ID : 181542
Revision : 4
Created on : 6/10/2019
Published on : 6/10/2019
Exists online : False
Views : 171