access2002: type mismatch

G

Guest

Encounter the following problem:
dim dbs as database, rst as recordset
set dbs= CurrentDB
set rst= dbs.OpenRecordset("xxx",dbOpenDynaset)
error message:"type mismatch"
please advise
 
J

Jeff Conrad

in message:
Encounter the following problem:
dim dbs as database, rst as recordset
set dbs= CurrentDB
set rst= dbs.OpenRecordset("xxx",dbOpenDynaset)
error message:"type mismatch"
please advise

It sounds like you need to set a reference to the DAO object library.
Access 2000 and 2002 do not by default set a reference to the DAO library.
There is no "Database" in the ADO library.

To fix the References problem follow these steps:
- Open any module in Design view.
- On the Tools menu, click References.
- Scroll down to you get to Microsoft DAO 3.xx and check it.
- If you're using Access 97 that should be DAO 3.51 Object Library.
- If you're using Access 2000, 2002, or 2003 that should be DAO 3.6 Object Library.
- Close the References box again.
- Now re-compile again. Debug--Compile.
- Hopefully you should not see any more compile errors.

As good practice it may also be better to use this:

Dim MyDb As DAO.Database

....rather than:

Dim MyDb As Database

This helps to avoid confusion for Access (but you still have to
manually set a reference to DAO for 2000 and 2002).

And a quote from MVP Doug Steele:
"If you have both references, you'll find that you'll need to "disambiguate"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rsCurr as DAO.Recordset (to guarantee an ADO recordset, you'd use
Dim rsCurr As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset"
 

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

Similar Threads


Top