Type mismatch when opening recordset

S

SAC

I've never seen this error when opening a recordset.

I have:

Dim dbs as database, rst as recordset

Set dbs = currentdb

Set rst = dbs.openrecordset("Customers")

And I get a Type Mismatch error.

Any idea?

Thanks.
 
G

Guest

Try This :

Dim dbs as database, rst as recordset

Set dbs = DBEngine(0)(0)

Set rst = dbs.openrecordset("Customers",dbOpenDynaset)


Yanick
 
D

Duane Hookom

Make sure you have a reference set the the DAO library and be more explicit:

Dim dbs as DAO.database, rst as DAO.recordset
 
D

Dirk Goldgar

SAC said:
I've never seen this error when opening a recordset.

I have:

Dim dbs as database, rst as recordset

Set dbs = currentdb

Set rst = dbs.openrecordset("Customers")

And I get a Type Mismatch error.

Any idea?

Both the DAO and the ADO object libraries define a Recordset object. By
default, Access 2000-2002 sets a reference to ADO and not to DAO. Even
if you later add a reference to DAO, it defaults to a lower priority
than the ADO reference, though you can move it up in the priority list.

Therefore, by default, a declaration such as "Dim rs As Recordset" is
going to be declaring an ADO recordset. However, the Recordset and
RecordsetClone of a form in an MDB file are DAO recordsets. Hence, you
get a type mismatch when you try to assign the form's (DAO)
RecordsetClone to the (ADO) recordset you've declared.

To correct this, be sure you've added a reference to the Microsoft DAO
3.6 Object Library (via the Tools -> References... dialog in the VB
Editor), and either remove the ADO (Microsoft ActiveX Data Objects)
reference -- if you're not going to use it -- or qualify your
declaration of DAO objects with the "DAO." prefix, like this:

Dim rs As DAO.Recordset
 
S

SAC

That was it! The reference was after the active x so I moved it up.

As you suggest, I could have been more specific and that would have fixed it
also.

Thanks for your help!
 
S

SAC

It was a reference problem as I should have specified the objects as DAO.

Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top