AndrewWolford
MIS
I'm having a problem getting my code to run properly. Here's the overall process I'm trying to accomplish. I've got a table, from that table I'm running a query that pulls certain information, then exports the results of that query to Excel for charting purposes. Heres the code:
strSQL = "SELECT * FROM testdata;" 'easy query for example
db.QueryDefs("qryExcelExport"
.sql = strSQL
DoCmd.TransferSpreadsheet acExport, 8, "qryExcelExport", _
outfile, True
"qryExcelExport" is a pre-existing query that I change to whatever SQL code is in strSQL.
"outfile" is the name and path of the DB.
This code works, but if it is ran and the query errors out (for example strSQL contains a field name that isn't in the table), the next time I try to run this code I get the following error:
'table qryExcelExport already exists'
For some reason, access thinks qryExcelExport is a table, and I continue to get this error unless I rename the query. Then it works over and over, until I finally try to run the query with an error in it. How can I get access to not see it as a table. I thought a workaround might be creating the query in code, then deleting it if the query errors out. Does anyone know how to get rid of this error? Thanks for any help!
-Andrew
strSQL = "SELECT * FROM testdata;" 'easy query for example
db.QueryDefs("qryExcelExport"
DoCmd.TransferSpreadsheet acExport, 8, "qryExcelExport", _
outfile, True
"qryExcelExport" is a pre-existing query that I change to whatever SQL code is in strSQL.
"outfile" is the name and path of the DB.
This code works, but if it is ran and the query errors out (for example strSQL contains a field name that isn't in the table), the next time I try to run this code I get the following error:
'table qryExcelExport already exists'
For some reason, access thinks qryExcelExport is a table, and I continue to get this error unless I rename the query. Then it works over and over, until I finally try to run the query with an error in it. How can I get access to not see it as a table. I thought a workaround might be creating the query in code, then deleting it if the query errors out. Does anyone know how to get rid of this error? Thanks for any help!
-Andrew