PDA

View Full Version : DAO ISSUE WITH MS ACCESS 2008



ronakj16
02-10-2019, 12:23 PM
Hi,

I am just a beginner and trying below VBA Code-

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.

OBP
02-10-2019, 03:28 PM
Personally I prefer not to declare the type of VBA dataset that I am going to use.
Your error messages come from that declaration which is incomplete.

For recordset use I use code like the following

Dim rs As Object
' CHANGE THE TABLE NAME HERE
Set rs = CurrentDb.OpenRecordset("Customers")
msgbox rs.ID
msgbox rs.Company

rs.close
set rs = Nothing

ronakj16
02-11-2019, 02:09 AM
Thanks for the Quick response.

I tried your Code and it shoeing same error-"Name 'DBEngine' is not declared. "
23717

OBP
02-11-2019, 02:54 AM
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.

ronakj16
02-11-2019, 03:16 AM
Hello OBP,
I am running This on VB Studio 2008 with DB MS Access 2007.
Yes i have included DAO under Reference.23718

OBP
02-11-2019, 03:32 AM
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.