Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 17th, 2004, 06:49 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mismatch Error on OpenRecordset

I am receiving a mismatch error on my Set line for a recordset that is opening a table in the current database. I have reviewed rhe Dim and Set statements over and over and they appear correct. No matter what I do, the error occurs. I have not had this problem in earlier versions of Access.

Any thoughts?

Code:

Dim pay As Recordset
Set pay = db.OpenRecordset("Earnings")

Yes, there is a table in the current database named Earnings.
 
Old February 17th, 2004, 07:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try

Dim pay As New Recordset



Rand
 
Old February 17th, 2004, 07:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My DAO is rusty but ...

Code:
Dim db As Database
Dim pay As Recordset

Set db = CurrentDb()
Set pay = db.OpenRecordset("Earnings")
etc...


Rand
 
Old February 17th, 2004, 07:29 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the recordset is DAO then

Dim rstPay as DAO.Recordset
Set rstPay = CurrentDB.OpenRecordset("Earnings")


HTH,
Mike
 
Old February 19th, 2004, 11:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear MikeDU,

The reason you are getting a mismatch is that you are using DAO. ADO is the newer (and preferred) form of data access.

You may use either one, BUT you need to know the following caveat.

Recordset can be either DAO or ADO (ADODB). When Access 2000 (or later) sees "Recordset" it sets the default type as either ADODB or DAO depending upon which one is first in the reference list. This may vary from computer to computer - ie. the code you wrote may work on one machine and not on the next one.

The only way to guarantee that the correct type is used every time is to explicitly specify it as ADODB or DAO, for example:
Code:
Dim pay As ADODB.Recordset

or
Code:
Dim pay As DAO.Recordset

Other than hard coding the type (ADODB or DAO) or re-ordering the reference list on each computer, I don't know of any other way to force the default.

In your case, use the DAO type.

Once you specify the type explicitly, you must then make certain that the correct reference is installed on each computer that uses the code. If the reference is MISSING you will get a different error.

After getting bitten by this feature many times, I now try to specify the data access type (DAO or ADODB) as above.


Rand





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Mismatch Error arholly SQL Server ASP 1 March 18th, 2008 02:34 AM
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
Mismatch error Sheraz Khan ASP.NET 2.0 Basics 3 May 16th, 2007 10:50 AM
Type Mismatch error Sheraz Khan Classic ASP Basics 0 May 16th, 2007 08:12 AM
OpenRecordset And Run-Time Error 13 Type Mismatch Pavesa Access VBA 5 March 22nd, 2005 05:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.