Im trying to export a query to specific columns in excel and im using this code.
I found on another thread here yesterday. I tried it on other querys and it works but doesn't work on this specific one. I get an error on the "set rst = currentDb" line. And to my knowledge it doesn't work because I have a between two dates filter in it. So when I run it, I get an error saying I have too few parameters, expecting 2. And I have no idea how to fix it...
Also it seems to be exporting the lookup id's not the value when exporting(on the query that it did work on)
THanks for your help, it's been pretty frustrating.
Code:
Dim objXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim rst As DAO.Recordset
Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open("filePath")
Set xlWS = xlWB.Worksheets("Sheet1")
Set rst = CurrentDb.OpenRecordset("queryName")
xlWS.Range("E2").CopyFromRecordset rst
xlWB.Save
rst.Close
Set rst = Nothing
I found on another thread here yesterday. I tried it on other querys and it works but doesn't work on this specific one. I get an error on the "set rst = currentDb" line. And to my knowledge it doesn't work because I have a between two dates filter in it. So when I run it, I get an error saying I have too few parameters, expecting 2. And I have no idea how to fix it...
Also it seems to be exporting the lookup id's not the value when exporting(on the query that it did work on)
THanks for your help, it's been pretty frustrating.