Quick syntax help needed please

  • Thread starter rfuscjr via AccessMonster.com
  • Start date
R

rfuscjr via AccessMonster.com

I have some VBA being used to delete table. There are spaces in that table
name so my statement below errors out. I think I need quotes around the
table name but have been unable to get the syntax down.


DoCmd.RunSql "Delete * From tblFinal Business plan"

How do I account for the fact that the table name has spaces....
 
F

fredg

I have some VBA being used to delete table. There are spaces in that table
name so my statement below errors out. I think I need quotes around the
table name but have been unable to get the syntax down.

DoCmd.RunSql "Delete * From tblFinal Business plan"

How do I account for the fact that the table name has spaces....

A good reason why spaces should never be used in table or field names.
Enclose the name within brackets.

DoCmd.RunSql "Delete * From [tblFinal Business plan]"
 
D

Dale Fye

Any time you leave a space in a table or field name, you are left with the
situation that you must always refer to it by wrapping the name in brackets.
Try:

DoCmd.RunSql "Delete * From [tblFinal Business plan]"

personally, I prefer:

Currentdb.Execute "Delete * From tblFinal Business plan", dbfailonerror

This allows me to trap for errors in the process, handle those errors, then
return to my code.
 
R

rfuscjr via AccessMonster.com

Thaks all...the spaces are not my doing!
Dale said:
Any time you leave a space in a table or field name, you are left with the
situation that you must always refer to it by wrapping the name in brackets.
Try:

DoCmd.RunSql "Delete * From [tblFinal Business plan]"

personally, I prefer:

Currentdb.Execute "Delete * From tblFinal Business plan", dbfailonerror

This allows me to trap for errors in the process, handle those errors, then
return to my code.

----
HTH
Dale
I have some VBA being used to delete table. There are spaces in that table
name so my statement below errors out. I think I need quotes around the
[quoted text clipped - 3 lines]
How do I account for the fact that the table name has spaces....
 

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