How do I enable DAO in Access 2003 (1 Viewer)

Theguyinthehat

Registered User.
Local time
Yesterday, 19:24
Joined
Aug 17, 2009
Messages
46
I still can't compile with the line
dim rst as DAO.Recordset

and I've looked everywhere for a way to 'enable' DAO without any luck. Can anyone help me out?
 

boblarson

Smeghead
Local time
Yesterday, 19:24
Joined
Jan 12, 2001
Messages
32,059
In the VBA window you go to TOOLS > REFERENCES and the scroll down until you find

Microsoft DAO 3.51

or

Microsoft DAO 3.6

and check the box next to it.
 

boblarson

Smeghead
Local time
Yesterday, 19:24
Joined
Jan 12, 2001
Messages
32,059
Actually that would be

Microsoft DAO 3.51 Object Library

or

Microsoft DAO 3.6 Object Library
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:24
Joined
Sep 12, 2006
Messages
15,652
if you dont want to have to qualify your references with dao, you just need to make sure that the reference for DAO is above the one for ADO (activex data objects)
 

Banana

split with a cherry atop.
Local time
Yesterday, 19:24
Joined
Sep 1, 2005
Messages
6,318
gemma-

While this is true that ordering can avoid the extra typing, it can be worse if the references gets broken. For example, suppose we put the file on computer that didn't have DAO library (at least not the same version) but happened to have the correct version for ADO. What would happen is that the program seems to run okay then bugs associating with accessing DAO methods that's not available in ADO start showing up. This could be more time consuming and confusing than getting a broken reference right at the start, alerting the user/developer to the problem and fixing it accordingly.
 

boblarson

Smeghead
Local time
Yesterday, 19:24
Joined
Jan 12, 2001
Messages
32,059
I would always be explicit. It doesn't matter that it might not need to be, but it is good practice to explicitly declare them. Of course you could just use late binding too and then you don't need to use either.
 

Banana

split with a cherry atop.
Local time
Yesterday, 19:24
Joined
Sep 1, 2005
Messages
6,318
For DAO, there's also a different way that requires neither early/late binding or explicit references; ChrisO demonstrated it, I think.

Code:
With CurrentDb.OpenRecordset("SELECT ...")
   ...
End With

Supposedly, it'd always succeed since we're walking the DAO object model. I don't think we can do the same thing with ADO, though.
 

Users who are viewing this thread

Top Bottom