Database variable change from 97 to 2003

  • Thread starter Thread starter Susan
  • Start date Start date
S

Susan

I have a couple of databases that were created with Access
97 and have been converted. The modules converted and
work fine. When I try to create or modify any of these
modules, however, I get errors on the database variable
declaration. I use the following form:

dim dbs as database, rcd as recordset
set dbs = currentdb()
set rcd = dbs.openrecordset("tblWhatever", dbopentable)

Why won't this code work in Access 2003? How should I
define a file without the database?
 
Access 97 used DAO by default. Access 2003 has references set to both DAO
and ADO and, perhaps unfortunately, the ADO reference is set higher in
precedence.

Try changing your declarations to:

Dim dbs As DAO.Database, rcd As DAO.Recordset

The first, DAO.Database, isn't strictly necessary, since Database is only an
object in the DAO model. (I think it's a good habit to get into, though.)
The second one, though, is what's causing your problems, because Recordset
is an object in both models. (BTW, should you want to guarantee you're
getting an ADO recordset, use Dim rcd As ADODB.Recordset)
 
Back
Top