Microsoft Knowledge Base Email Alertz

If you dimension an object as a Recordset and then set that object to databaseobject.OpenRecordset(source), you may get the following error message:

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 181542 - Last Review: January 12, 2006 - Revision: 4.3

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

This article was previously published under Q181542

On This Page

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

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.

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
				

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.

APPLIES TO
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbprb KB181542
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

J Castillo - jcastillomedina NOSPAM-AT-NOSPAM lycos.es Report As Irrelevant  
Written: 6/22/2004 6:40 AM
helpful It is increible how funny can be to program in visual basic aplications with no help from the compiler in any case

Trevor Lyle - tjlyle NOSPAM-AT-NOSPAM yahoo Report As Irrelevant  
Written: 8/31/2004 8:47 AM
Thank you! I struggled for ages to resolve this! Thanks for your help :0)