PDA

View Full Version : FROM syntax not recognizing table



RKeev
03-15-2012, 09:25 AM
Good day all, I am hoping someone can shine the light on my mistakes.
I have an ADO code the runs in excel pulling info from an MS access DB.
The issue is when I pull FROM a table that has one word it works fine but if the table has more than one word with a space etc it does not work.
If i replace the "Profiles 3-4" below with one word like "Helmet" it works but i have so many tables in my DB renaming all to a single word is not realistic. Any help would be apprecited.
BTW im not new to excel VBA but access i am ver much a novice.
Thx,
RKeev
This is the selection of code where it errors:

Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT * FROM Profiles 3-4 WHERE BDE = 'HBCT' "

hansup
04-05-2012, 11:11 AM
If possible, rename the table to a single word with no spaces, punctuation marks, etc. ... begin the name with a letter, and use only letters, digits, and the underscore character for the rest of the name.

If you must keep that name, surround it with square brackets to avoid confusing the database engine.


Src = "SELECT * FROM [Profiles 3-4] WHERE BDE = 'HBCT' "

geekgirlau
05-02-2012, 05:20 PM
hansup makes an excellent point. It's a good idea when setting up your database to not include spaces in the name of anything - tables, fields, queries, forms ...

I'd suggest you do some reading on the Leszynski/Reddick naming conventions - it's a good habit to get into, and makes your database much easier to maintain.