I'm attempting to copy the results of an access query and paste it into an excel tab. I've googled around but can't seem to get it to work, I get the error "Error 3343: Unrecognized database format" so I assume it has something to do with the references I have checked.
Does anyone know the correct references I need to get this to work?
References:
Visual Basic For Application
Microsoft Excel 14.0 Object Library
OLE Automation
Microsoft Office 14.0 Object Library
Microsoft ActiveX Data Objects 2.8 Library
Microsft DAO 3.6 Object Library
Sub Query()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sql As String
Dim iCol As Integer
Sheets("DataDump1").Select
With Selection.ClearContents
End With
Set db = OpenDatabase("C:\Folder\DatabaseName.accdb")
Set rst = db.OpenRecordset("Query 1")
For iCol = 1 To rst.Fields.Count
ActiveSheet.Cells(1, iCol) = rst.Fields(iCol - 1).Name
Next iCol
ActiveSheet.Range("A2").CopyFromRecordset rst
rst.Close
db.Close
Set rst = Nothing
Set db = Nothing
End Sub