/ Published in: Visual Basic
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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 _ ("D:\my Documents\Database2.accdb") Set MyQueryDef = MyDatabase.QueryDefs("Query3") With MyQueryDef .Parameters("[jahrpar]") = Range("A1").Value End With 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