the Manx Man's MS Access Tips Pages

Receive New Tips
by Email Weekly
to subscribe - click here

What Your
Computer Consultant
Doesn't Want You to Know
Click here to find out

need professional help with a database?
click here


Referencing DAO

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.

Example.

Dim db as database
Dim rst as recordset

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

If you start up 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)
rst.edit
... etc ...

 

index of tips click here for a
clean laugh
profit from the web