maianoel
asked on
Problem export query results
I am trying to export the result of a query named qryExport_results. I am using the following to do so:
DoCmd.TransferText acExportDelim, , "qryExport_results", strSaveFileName, True
The problem is that I get an error stating "Query must have at least one destination field". I am not sure what I am doing wrong. I tried to just disply the query to make sure it was working ok, and it appears it is. I am lost.
Thanks!
DoCmd.TransferText acExportDelim, , "qryExport_results", strSaveFileName, True
The problem is that I get an error stating "Query must have at least one destination field". I am not sure what I am doing wrong. I tried to just disply the query to make sure it was working ok, and it appears it is. I am lost.
Thanks!
ASKER
Does it have to be a path? Right now I am using the microsoft Save file dialog box to specify the path, which I am then assigning to strSaveFileName. It works OK for tables, but maybe queries are different?
well, try changing it and run the codes again.
What type of query is qryExport_results? Is it a SELECT query?
ASKER
OK, I tried changing the path to C:\results.csv and I still get the same error.
It's a SELECT query. the code is as follows:
SELECT *
FROM cbsofeed_less
WHERE (((cbsofeed_less.Trunc_Acc t)="035943 64") AND ((CDate([Month]))=#8/1/200 4#))
ORDER BY cbsofeed_less.Inv_Date;
It's a SELECT query. the code is as follows:
SELECT *
FROM cbsofeed_less
WHERE (((cbsofeed_less.Trunc_Acc
ORDER BY cbsofeed_less.Inv_Date;
try changing this
C:\results.csv
to
C:\results.txt
C:\results.csv
to
C:\results.txt
ASKER
ok, changing it to c:\results.txt worked fine. Is there a way to make this work with either .csv files or .xls files? (I get the same error when exporting to an excel file). I don't want the users to have to import the file into excel manually.
try adding to your references
Microsoft Excel xx Object library
tools>references
Microsoft Excel xx Object library
tools>references
ASKER
Nope, that did not work either. Still get the same error message. Could there be something wrong in my DoCmd statement? Funny that it works fine with a table, but not with a query.
Are you trying to export to an xls file? If you are, you have to use TransferSpreadsheet - TransferText will not let you export to file extensions other than csv and txt.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
shane, right now I am just trying to export the query results to a .csv file so the users can open it up in excel easily. after trying capricorn's suggestion above, it appears it will export to .txt just fine, but for some reason won't to .csv.
capricorn1, I will give your suggestion a try now and let you know.
Thanks to both of you for you help and suggestions!
capricorn1, I will give your suggestion a try now and let you know.
Thanks to both of you for you help and suggestions!
ASKER
Well, I added the Micrososft Office XX object library and then did a debug>compile (this alone was nice as I was able to get rid of some redundant code I had from early on) and all works perfectly now. Thanks for your help!
u r welcome!!!
DoCmd.TransferText acExportDelim, , "qryExport_results", strSaveFileName, True
--------------------------
like "C:\Filename"