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