Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Table already exists" error!?

Status
Not open for further replies.
Jul 8, 2002
61
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top