Public Sub DAOTest()
Dim myRecordset As dao.Recordset
Dim myDatabase As dao.Database
myDatabase = DBEngine("C:\temp\Northwind.accdb")
'Create the DAO-style Recordset
myRecordset = myDatabase.OpenRecordset(Name:="Customers", Type:=dbOpenTable)
MsgBox(myRecordset("ID"))
MsgBox(myRecordset("Company"))
End Sub
but it is Throwing 2 error-
Error 1 Name 'DBEngine' is not declared.
Error 2 Name 'dbOpenTable' is not declared.
Need help to solve this 'DAO' related issue. I am using VB2008 and MS Office 2007 and i have also included DAO under VBA Reference.
Are you running this in Access?
Have you set the VBA Reference Library Links?
It needs Visual Basic For Applications, Microsoft Access Object Library, OLE Automation & Micosoft Office Access database engine Object library.
I am not familiar with those references, only Access ones, so I don't know how you set them up to do the same as Access which requires Access library references to be set up as I listed.
Here is a screenshot of the Access References.