FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,366
- Office Version
- 365
- 2016
- Platform
- Windows
I realize many I'm might be behind the times here, but this query use to run, but not now.
I'm trying to pull some data from a query in an Access database, but get a debug on DAO.Database.
From some reading, DAO is ancient and should be using instead ADO.
I looked thru the References and clicked on Microsoft DAO 3.6 Object Library, but still get a error in loading DLL. I'm using 2016.
I'm trying to pull some data from a query in an Access database, but get a debug on DAO.Database.
From some reading, DAO is ancient and should be using instead ADO.
I looked thru the References and clicked on Microsoft DAO 3.6 Object Library, but still get a error in loading DLL. I'm using 2016.
Code:
Sub RunAccessQuery()
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Dim i As Integer
Set MyDatabase = DBEngine.OpenDatabase("C:\Users\fg\Desktop\New folder\ZalexCorp Restaurant Equipment and Supply.accdb")
Set MyQueryDef = MyDatabase.QueryDefs("Revenue by Period")
Set MyRecordset = MyQueryDef.OpenRecordset
Sheets("Main").Select
ActiveSheet.Range("A6:K10000").ClearContents
ActiveSheet.Range("A7").CopyFromRecordset MyRecordset
For i = 1 To MyRecordset.Fields.Count
ActiveSheet.Cells(6, i).Value = MyRecordset.Fields(i - 1).Name
Next i
End Sub