'Serving the Microsoft® Access
Community since 1997'

Free Samples
About Us



Referencing DAO in Microsoft® Access VBA

I use DAO exclusively. I have NEVER used ADO.

What is DAO? It is an acronym for Data Access Objects. The most important function of DAO is to provide you with a way to manipulate your data. The most common DAO object that you will see in my examples is the recordset object.

Why DAO? It was designed specifically for the Jet Engine, which is what stand-alone MS Access databases use. It is more efficient for some processes in Access.


    Dim db as database
    Dim rst as recordset

    set db=currentdb
    set rst = db.openrecordset("select * " & _
        "from tblSomeTable " & _
        "where somefield=" & somecriteria)
    ... etc ...

If you start up Microsoft® Access 2000 and type the above code into a VBA module in a new database, it will not work. Why? Because, by default, Access 2000 does not turn DAO on. You have to do that.

Just open up your VBA editor, go to the Tools menu, choose References, check off the ADO entry, find DAO 3.x, check it on, and exit the dialogue box. Now the code will work.

If you need to use both ADO and DAO, explicitly declare DAO references.

    Dim db as DAO.database
    Dim rst as DAO.recordset

    set db=currentdb
    set rst = db.openrecordset("select * " & _
        "from tblSomeTable " & _
        "where somefield=" & somecriteria)
    ... etc ...

How to Turn DAO on

To watch a 1 minute video that will show you how I turn DAO on whenever I create a new database in MS Access 2000, click on the photo below.

dao references on in MS Access 2000 (dao-on.jpg 20 Kbytes)

Note: This web site dedicated to MS Access database users is an independent publication of Richard W. Killey and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft® Corporation.


© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. - Privacy Policy