OpenRecordset - Run-time error '13'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

With reference to Microsoft DAO 3.6 Object Library and the following code

Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb
Set dbs = dbs.OpenRecordset("DHTS")

the code fails in the last statement with "Type mismatch" and Run-time error
13.

DHTS is a table in my database. I have identical code - but with different
table name - running other places - and I have had this happen other places
as well. What's the reason...?
 
You set the database as Recordset
Set dbs = dbs.OpenRecordset("DHTS")

change it to
Set rst = dbs.OpenRecordset("DHTS")
 
I assume you're running ACCESS 2000 or 2002 or 2003. In those versions, the
ADO library has higher priority than DAO (unless you've changed it
manually), and thus the Dim rst As Recordset step goes to the ADO library
and not the DAO library.

Disambiguate the dim statement:

Dim rst As DAO.Recordset
 
so embarassing.... this solved this issue. I was just blinded by the fact
that sometimes I really do get this error.
 
Back
Top