Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DAO references / Access 2007

61 views
Skip to first unread message

Pedroia@discussions.microsoft.com Dustin Pedroia

unread,
Feb 27, 2008, 9:44:04 AM2/27/08
to
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


Douglas J. Steele

unread,
Feb 27, 2008, 2:45:46 PM2/27/08
to
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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Dustin Pedroia" <Dustin Ped...@discussions.microsoft.com> wrote in message
news:E34EB6F4-5F6C-4022...@microsoft.com...

Swiniarski@discussions.microsoft.com Michal Swiniarski

unread,
Mar 5, 2008, 7:57:01 AM3/5/08
to
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

0 new messages