Delete From???

J

Jason Gyetko

I created the following function to clear the data in my database tables.
It works fine for tables with single word titles, but if there are titles
with two words seperated by a space like, Call ClearTables("Two Words"),
then I get the following message: "The Microsoft Jet database engine cannot
find the table or query 'Two'. Make sure it exists and that its name is
spelled correctly". How do I get it to accept tables with spaces in their
names? Thanks in advance.

Function ClearTables(TableName As String)
DoCmd.RunSQL ("Delete From " & TableName)
End Function
 
B

Bryon

I created the following function to clear the data in my database tables.
It works fine for tables with single word titles, but if there are titles
with two words seperated by a space like, Call ClearTables("Two Words"),
then I get the following message: "The Microsoft Jet database engine cannot
find the table or query 'Two'. Make sure it exists and that its name is
spelled correctly". How do I get it to accept tables with spaces in their
names? Thanks in advance.

Function ClearTables(TableName As String)
DoCmd.RunSQL ("Delete From " & TableName)
End Function

In SQL, words with spaces can have square brackets or quotes around them.
You want:
DoCmd.RunSQL ("Delete From [" & TableName & "]")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top