This article was previously published under Q313233
Moderate: Requires basic macro, coding, and interoperability skills.
For a Microsoft Access 2000 version of this article, see 199064.
This article applies only to a Microsoft Access database (.mdb).
When you open or convert a database that was created in a version of Access earlier than Access 2000, and you attempt to run or compile older code that uses Data Access Objects (DAO), you may receive compile errors.
This issue can occur because Access 2002 does not have compatibility type libraries.
To resolve this issue, update the code to the current DAO syntax. For example, rewrite the code to use the object Recordset instead of the Access version 1.0 object Dynaset.For more information about and examples of how to update older DAO code, in the VisualBasic Editor, click Microsoft Visual Basic Help on theHelp menu, type "DAO Object Library Compatibility" in the Office Assistant orthe Answer Wizard, and then click Search to view the topic.
Versions of Access that are earlier than Access 2000 can successfully compile and run older syntax. For example, the object model for DAO in Access 2.0 is significantly different from the object model for DAO in Access 1.0, but DAO in Access 2.0 still allows the code from Access 1.0 to compile and run. You do not have to reference a type library.
Access 7.0 and Access 97 include the DAO 2.5/3.0 and DAO 2.5/3.5 compatibility type libraries. Access 7.0 and Access 97 use these libraries by default for converted Access 2.0 databases. Therefore, the older code from Access 1.0 still works in Access 7.0 and Access 97.
Because Access 2002 has no compatibility type libraries, DAO code that uses some of the older syntax may not run.
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
Steps to Reproduce This Issue
On a computer that runs Access 97, open the Northwind.mdb sample database.
Create a new module named DAOTest.
Type the following procedure:
Sub TestOpenRec() Dim dbs As Database Set dbs = CurrentDb Dim dyn As Dynaset Set dyn = dbs.CreateDynaset("Orders") MsgBox dyn.Fields.CountEnd Sub
On the Tools menu, click References.
Make sure that the Microsoft DAO 3.5 Object Library check box is not selected.
Click to select the Microsoft DAO 2.5/3.5 Compatibility Library check box, and then click OK.
Press CTRL+G to open the Debug window.
In the Debug window, type TestOpenRec, and then press ENTER.
Note that you do not receive any errors and that the number 14 is displayed in the message box. This number is the number of fields in the Orders table.
Close the Northwind.mdb sample database, and then copy the Access 97 Northwind database to a computer that runs Access 2002.
Open the Access 97 version of Northwind.mdb in Access 2002.
Note that you receive the following error messages the first time that you open the database in Access 2002:
There were compilation errors during the conversion or enabling of this database. This might be due to old DAO syntax that is no longer supported. For an example on how to fix up the code, click Help.
There were compilation errors during the conversion or enabling of this database. The database has not been saved in compiled state. The performance of this database will be impaired because Microsoft Access will need to recompile the database for each session. For information on improving performance, click Help.
Press CTRL+G to open the Immediate window.
In the Immediate window, type TestOpenRec, and then press ENTER. You receive the following error message:
Your Microsoft Access database or project contains a missing or broken reference to the file 'dao2535.tlb' version 3.5.
To ensure that your database or project works properly, you must fix this reference. To learn how to fix this reference, click Help.
You then receive the following error message:
Compile error: Can't find project or library.
On the Tools menu, click References. Note that Microsoft DAO 2.5/3.5 Compatibility Library is listed as missing. If you click to clear the Microsoft DAO 2.5/3.5 Compatibility Library check box and then click OK, you receive the following error message:
Compile error: User-defined type not defined.
For this DAO example to work in Access 2002, rewrite the procedure asin the following example to use the object Recordset instead of the Access version 1.0 object Dynaset:
Sub TestOpenRec() Dim dbs As DAO.Database Set dbs = CurrentDb Dim rst As Recordset Set rst = dbs!Orders.OpenRecordset(dbOpenDynaset) MsgBox rst.Fields.CountEnd Sub