SQL statement in VBA

  • Thread starter Michael Malinsky
  • Start date
M

Michael Malinsky

Hello all,

I know how to create an SQL statement in VBA, but the problem that I'm
running into with this one particular database (not of my design) is
that the tables and queries have names that contain spaces (i.e.,
Customer List). Apparently the SQL statement doesn't like the space in
the table/query name. I've tried a couple of different things without
success. Can anyone help with with this problem?

Thanks,
Mike.
 
T

Tom Ogilvy

Have you tried recording a macro using Get external data. You can then look
at the SQL portion and get some hints. I think the answer is to use single
quotes, but don't do that much with SQL.
 
R

Robert Bruce

Roedd said:
I know how to create an SQL statement in VBA, but the problem that I'm
running into with this one particular database (not of my design) is
that the tables and queries have names that contain spaces (i.e.,
Customer List). Apparently the SQL statement doesn't like the space
in the table/query name. I've tried a couple of different things
without success. Can anyone help with with this problem?

What couple of things? You're in danger here of getting loads of replies
with stuff you've already tried.

Put the field names in [] square brackets.

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.
 
R

Robert Bruce

Roedd said:
Put the field names in [] square brackets.

Oh dear. Typo. I meant Table and/or query names, though I generally put all
Field, Table AND query names in square brackets just to be on the safe
side - Jet in particular has some obscure and seemingly ever-changing
reserved words.

--
Rob

http://www.asta51.dsl.pipex.com/webcam/

This message is copyright Robert Bruce and intended
for distribution only via NNTP.
Dissemination via third party Web forums with the
exception of Google Groups and Microsoft Communities
is strictly prohibited and may result in legal action.
 
M

Michael Malinsky

Tom,

Thanks for that suggestion. The answer was to enclose the table/query
name in backticks (``).

Mike.
 
T

Tom Ogilvy

Thanks for coming back with that. I have to confess that is what I was
thinking of, but didn't know what to call them or really exactly what they
were (and hoped single quotes would work as well). <g>
 

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