You may receive compile errors after you open or convert a database that has older DAO code in Access 2002

Article translations Article translations
Article ID: 313233 - View products that this article applies to.
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).

Expand all | Collapse all

On This Page

SYMPTOMS

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.

CAUSE

This issue can occur because Access 2002 does not have compatibility type libraries.

RESOLUTION

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 Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "DAO Object Library Compatibility" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

MORE INFORMATION

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

  1. On a computer that runs Access 97, open the Northwind.mdb sample database.
  2. Create a new module named DAOTest.
  3. 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.Count
    End Sub
    					
  4. On the Tools menu, click References.
  5. Make sure that the Microsoft DAO 3.5 Object Library check box is not selected.
  6. Click to select the Microsoft DAO 2.5/3.5 Compatibility Library check box, and then click OK.
  7. Press CTRL+G to open the Debug window.
  8. 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.
  9. Close the Northwind.mdb sample database, and then copy the Access 97 Northwind database to a computer that runs Access 2002.
  10. 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.
  11. Press CTRL+G to open the Immediate window.
  12. 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.
  13. 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.
  14. For this DAO example to work in Access 2002, rewrite the procedure as in 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.Count
    End Sub
    					

Properties

Article ID: 313233 - Last Review: August 18, 2004 - Revision: 4.0
APPLIES TO
  • Microsoft Access 2002 Standard Edition
Keywords: 
kberrmsg kbprb KB313233

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com