DAO references / Access 2007

D

Dustin Pedroia

while using an Access 2007 .accdb file I can access the dao. object very
easily.
the following code in VBA works well :
Function getrecordcount(strTableName As String) As Long
Dim dbCurrent As DAO.Database
Set db = CurrentDb
Dim rstRecords As DAO.Recordset
Dim rstRecords2 As DAO.Recordset2
Set rstRecords = db.OpenRecordset(strTableName, dbOpenForwardOnly)

all the DAO.xxx references are recognized and are generated from the
Microsoft Office 12.0 Access database engine Object Library, acedao.dll
as evidenced by the ability to reference Recordset2.

but when similar code is generated in Visual Basic 2005 I am unable to
access the dao. object library using the same dao. naming conventions. for
some reason it forces me to use Microsoft.Office.Interop.Access.Dao.xxx in
every statement instead of just dao.

similar code in Visual Basic 2005 is :
Function getrecordcount(ByVal strTableName As String) As Long
Dim dbEngine As Microsoft.Office.Interop.Access.Dao.DBEngine
Dim db As Microsoft.Office.Interop.Access.Dao.Database
dbEngine = New Microsoft.Office.Interop.Access.Dao.DBEngine()
db = dbEngine.OpenDatabase("filename.accdb")
Dim rstRecords As Microsoft.Office.Interop.Access.Dao.Recordset
Dim rstRecords2 As Microsoft.Office.Interop.Access.Dao.Recordset2
rstRecords = db.OpenRecordset("strTableName", dbOpenForwardOnly)
rstRecords2 = db.OpenRecordset("strTableName", dbOpenForwardOnly)

and dbOpenForwardOnly generates a compile error of "is not declared"
while
Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum.dbOpenForwardOnly works
perfectly.

any ideas why dao. naming convention don't work ?
and why constants like dbOpenForwardOnly don't work ?
and why long naming like
Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum.dbOpenForwardOnly
is required ?

thanks

I do have the Microsoft Office 12.0 Access database engine Object Libary
added in Visual Basic 2005.
in VBA this object libary is located as c:\Program Files\Common
Files\Microsoft Shared\Acedao.dll
in VB 2005 it has a path of
c:\windows\assembly\GAC\Microsoft.Office.Interop.Access.Dao\12.0.0.__71e9bce111e9429c\Microsoft.Office.Interop.Access.Dao.dll
 
D

Douglas J. Steele

I think you'd be best off asking in a newsgroup related to VB.Net (which is
what Visual Basic 2005 is)

Access uses VBA, not .Net.
 
M

Michal Swiniarski

Use this

Dim dbEngine As Dao.DBEngine
Dim db As Dao.Database
Dim dbEngine = New Dao.DBEngine()
db = dbEngine.OpenDatabase("filename.accdb")
Dim rstRecords As Dao.Recordset
Dim rstRecords2 As Dao.Recordset
rstRecords = db.OpenRecordset("SQL text")
rstRecords2 = db.OpenRecordset("SQL text")

if you want to get data from database use
rstRecordset(column_index).value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top