How to open a database in DAO via VB.NET to grab all table, query, form, report and coding module names?

I get an unrecognized database format on any Access database that I try to open with DAO.  Am I missing an incorrect syntax on the OpenDatabase part?  This happens with any database that I try to open.
Private Sub Assign_Objects(ByVal sDB As String)

    m_Tables = New Collection
    m_Reports = New Collection
    m_Queries = New Collection
    m_Forms = New Collection
    m_Modules = New Collection
    m_Macros = New Collection

    Dim sMsg As String
    Dim db As dao.Database
    Dim ctnr As dao.Container
    Dim DAODBEngine_definst As New dao.DBEngine()
    
    db = DAODBEngine_definst.OpenDatabase(sDB, False, False, "")

    For Each tbl In db.TableDefs

      If Not tbl.Name Like "MSys*" And Not Microsoft.VisualBasic.Left(tbl.Name, 3) = "~sq" Then
        lValueCount = lValueCount + 100
        pbUpdate.Value = lCounter + lValueCount
        sMsg = "Assigning table: " & tbl.Name
        Msg_This(sMsg)
        m_Tables.Add(Item:=tbl.Name)

      End If

    Next

    ctnr = db.Containers("Reports")
    For Each rpt In ctnr.Documents

      If Not Microsoft.VisualBasic.Left(rpt.Name, 3) = "~sq" Then
        lValueCount = lValueCount + 100
        pbUpdate.Value = lCounter + lValueCount
        sMsg = "Assigning report: " & rpt.Name
        Msg_This(sMsg)
        m_Reports.Add(Item:=rpt.Name)

      End If

    Next


    For Each qdf In db.QueryDefs

      If Not qdf.Name Like "MSys*" And Not Microsoft.VisualBasic.Left(qdf.Name, 3) = "~sq" Then
        lValueCount = lValueCount + 100
        pbUpdate.Value = lCounter + lValueCount
        sMsg = "Assigning query: " & qdf.Name
        Msg_This(sMsg)
        m_Queries.Add(Item:=qdf.Name)

      End If

    Next

    For Each doc In db.Containers("Forms").Documents

      If Not Microsoft.VisualBasic.Left(doc.Name, 3) = "~sq" Then
        lValueCount = lValueCount + 100
        pbUpdate.Value = lCounter + lValueCount
        sMsg = "Assigning form: " & doc.Name
        Msg_This(sMsg)
        m_Forms.Add(Item:=doc.Name)

      End If

    Next doc

    ctnr = Nothing
    db.Close()
    db = Nothing
    Exit Sub

  End Sub

Open in new window

LVL 1
stephenlecomptejrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You need a reference to the correct version of DAO

Microsoft Office 12.0 Access database engine Object Library

Which is the "acedao.dll" file.

BTW, this would be a better solution than your other question.
0
stephenlecomptejrAuthor Commented:
When all I have is Microsoft Access 12.0 Object LIbrary as a reference - I  get type 'dao.database is not definied per image file.

When I add the Microsoft DAO 3.6 Object Library - I get no build errors but the same error -
unrecognized database format.


dao-not-working.png
0
Helen FeddemaCommented:
Here is some code (regular VBA, not VB.NET, but it may be helpful) for opening another database (note that for some purposes you need an Access Application variable, for others a DAO Database variable):

Public Sub OpenAnotherDatabase()
'Created by Helen Feddema 14-Feb-2010
'Last modified by Helen Feddema 14-Feb-2010

   Dim appAccess As New Access.Application
   Dim strDBNameAndPath As String
   Dim dbs As DAO.Database
   Dim rst As DAO.Recordset
   Dim dbe As DAO.DBEngine
   
   'Change to your db name and path
   strDBNameAndPath = "G:\Documents\Access 2002-2003 Databases\General.mdb"
   appAccess.Visible = True
   appAccess.OpenCurrentDatabase filepath:=strDBNameAndPath, _
      exclusive:=False
      
   'Run a procedure
   'appAccess.Run "PrintOrdersReport"
   
   'Run a macro
   'appAccess.DoCmd.RunMacro "mcrPrintOrdersReport"
   
   'Run an action query
   'appAccess.DoCmd.OpenQuery "qryDeleteSomeOrders"
   
   'Run SQL code
   strSQL = "DELETE tblOrders.ShippedDate FROM tblOrders WHERE ShippedDate = #8/4/1994#;"
   Debug.Print "SQL string: " & strSQL
   'appAccess.DoCmd.RunSQL strSQL
   
   'Iterate through a recordset
   Set dbe = appAccess.DBEngine
   Set dbs = dbe.OpenDatabase(strDBNameAndPath)
    
   Set rst = dbs.OpenRecordset("tblCategories")
   Do Until rst.EOF
      Debug.Print rst![CategoryName]
      rst.MoveNext
   Loop
   rst.Close
    
   Set dbs = Nothing
   Set appAccess = Nothing
   
End Sub

Open in new window

0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Helen FeddemaCommented:
As far as getting table and other object names is concerned, you can use the DAO Database TableDefs and QueryDefs collections to get the names of tables and queries, and the Access Application.CurrentProject's AllForms, AllMacros, AllModules and AllReports collections for those object names.
0
PaulHewsCommented:
DAO 3.6 will only work with MDB files.  The accdb format is not supported by DAO 3.6.  For that you have to reference

Microsoft Office 2007 Access database engine Object Library

C:\Program Files\Microsoft Office\Office12\acedao.dll

This is NOT the same as "Microsoft Access 12.0 Object Library" which would be the automation library.



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stephenlecomptejrAuthor Commented:
You mean this one.
Office-DAO-problem.png
0
stephenlecomptejrAuthor Commented:
Thank you very much for the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.