Consulting

Results 1 to 6 of 6

Thread: DAO ISSUE WITH MS ACCESS 2008

  1. #1
    VBAX Regular
    Joined
    Feb 2019
    Posts
    23
    Location

    DAO ISSUE WITH MS ACCESS 2008

    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.

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Feb 2019
    Posts
    23
    Location
    Thanks for the Quick response.

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

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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.

  5. #5
    VBAX Regular
    Joined
    Feb 2019
    Posts
    23
    Location
    Hello OBP,
    I am running This on VB Studio 2008 with DB MS Access 2007.
    Yes i have included DAO under Reference.Capture.jpg

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •