Dropping an Error Table

  • Thread starter Thread starter Access::Student
  • Start date Start date
A

Access::Student

Hello,
I'm drying to use VBA to delete an auto-generated error table but I can't
figure it out.
What I'm doing is running the following script from a button:

Private Sub Update_Assets_Click()
Application.DoCmd.SetWarnings False
DoCmd.RunSavedImportExport "Update_Assets"
DoCmd.OpenQuery "Add_Assets"
DoCmd.OpenQuery "Update_Assets"
DoCmd.RunSQL "DROP TABLE Database_Export;"
Application.DoCmd.SetWarnings True
End Sub

That works fine, but the Import step sometimes generates a table called
"Database_Exports$_ImportErrors" . What I tried to do was add the following
line after the other SQL line:

DoCmd.RunSQL "DROP TABLE Database_Export$_ImportErrors;"

But I get an error message and the script crashes. I have no idea why. Any
ideas?

Syntax error in DROP TABLE or DROP INDEX. (Error 3295)
 
It's the $ sign. If you remove it, you can drop the table. I attempted to
surround the table name using combinations of " and ' but can't get it to
work.
 
Thanks for the reply.
I had considered that, but the problem is that it's an auto-generated table,
so I can't pick the name. I don't think there's anything I can change so that
it removes the '$'.

I'm not sure what to do.
 
There should be a way to surround the table name with a combination of single
and double quotation marks so that it doesn't see the $. Something like below:

DROP TABLE "'Database_Export$_ImportErrors'";

DROP TABLE ""'Database_Export$_ImportErrors'"";
 
Access::Student said:
DoCmd.RunSQL "DROP TABLE Database_Export$_ImportErrors;"

But I get an error message and the script crashes. I have no idea why. Any
ideas?

Syntax error in DROP TABLE or DROP INDEX. (Error 3295)

Try brackets around the table name:

DoCmd.RunSQL "DROP TABLE [Database_Export$_ImportErrors];"
 
Back
Top