Link to home
Create AccountLog in
Avatar of geeta_m9
geeta_m9

asked on

Creating a command to export the results of a query to a spreadsheet

I would like to create a command so that when the user clicks on a button, the results of a query will be exported to an Excel spreadsheet. I know how to do this for a table, but would I do it for a query? The name of my query is "qJoinThreeTables".
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

You use extactly the same process. Replace atable name with a query name. Can't remember off the top of my head whether you specifiy the source as a table (actable), if so, change that to a query (acQuery). In all other respects thay are the same.


Kelvin
Avatar of geeta_m9
geeta_m9

ASKER

I tried that, but it doesn't seem to work.
This is the command I used:

DoCmd.TransferSpreadsheet acExport, 10, "qJoinThreeTables", "c:\Users\Documents\ApplicationsStatementsReviews.xlsx", True

Perhaps I need to execute the query first.
I modified the command slightly and now it seems to work. Not sure why it didn't work before.

DoCmd.TransferSpreadsheet acExport, , "qJoinThreeTables", "c:\Users\Documents\ApplicationsStatementsReviews.xlsx", False
ASKER CERTIFIED SOLUTION
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
The 10 was Office 2002 (if I am not mistaken), which is why you could not create a xlsx file. They were introducted in Office 2007 (Office 12). Office 11 did have filters to manage them, but don't think they went back any earlier
Thanks!