Hello,
I am wondering why my macro will not run. I am not skilled in Visual Basic. I am trying to import an Access parameter query into Excel. Any help would be appreciated.
Access database name: "Steelfab Purchasing20210408"
Query name is: "Spectrum Export Qry"
Query parameter is "Enter PO"
Excel sheet that I want the data to go to is called "DataDump"
Following is the macro language.
Sub AccParam() 'Excel VBA to import a parameter query from Access into Excel
Dim MyDatabase As DAO.Database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset
Set MyDatabase = DBEngine.OpenDatabase("E:\Steelfab Purchasing20210408.accdb")
Set MyQueryDef = MyDatabase.QueryDefs("qrySpectrum Export Qry")
Sheet1.[A2:R1100].DataDump.ClearContents 'Range to Clear
MyQueryDef.Parameters("[Enter PO]") = DataDump.[a2].Value
Set MyRecordset = MyQueryDef.OpenRecordset 'Open the query
DataDump.Range("A11").CopyFromRecordset MyRecordset
End Sub
Bookmarks