NOTE: This section references Microsoft DAO. DAO is not used in Microsoft Access projects (*.adp), but the same concepts regarding missing object libraries apply.
Not having a reference to the Microsoft DAO Object Library is one of the
most common reasons for the error described in the "Symptoms" section in Access databases (*.mdb). If the reference is missing, you may receive this error on many common DAO commands such as:
If you receive this error on a common DAO object, you need to add the
following reference:
Microsoft DAO 3.6 Object Library
Explicitly Declaring DAO and ADO Objects
A common reference conflict occurs when you have references to both
the Microsoft DAO Object Library (DAO) and the Microsoft ActiveX Data
Objects Library (ADO). This is because these two libraries contain objects
with the same name, such as
Recordset. To avoid any compile errors in the case where you add another object library reference that uses the same object names, it is good practice to include "DAO." in the declaration of any DAO objects. Likewise, when declaring ADO objects, include "ADODB." in
the declaration. This is illustrated below using the
Recordset object as an example:
Example 1: DAO Objects
Reference: Microsoft DAO 3.6 Object Library
Declaration: Dim myRecordset as DAO.Recordset
Example 2: ADO Objects
Reference: Microsoft ActiveX Data Objects 2.1 Library
Declaration: Dim myRecordset as ADODB.Recordset
NOTE: By explicitly declaring the object as ADO or DAO, the position of the checked reference on the references list is not an issue.
Steps to Reproduce Behavior
- Create a module and type the following procedure:
Function Test()
Dim db as DAO.Database
End Function
- On the Tools menu, click to clear the Microsoft DAO Object Library check box.
- To test this function, type the following line in the Immediate window, and then press ENTER:
Note that you receive the error message mentioned in the "Symptoms"
section.