Expected: end of statement error

G

Guest

I have pasted the SQL from a query, that I have tested and runs OK, into a
Docmd.RunSQL statement but I get an error 'Expected: end of statement'.

The problem seems to be associated with a DMax statement which is written
DMax("[myField]","myTable"). The myField text is highlighted when the error
is reported and I suspect I have to add or replace some parentheses. I've
tried all sorts of combinations with no luck.

Any ideas?

Thanks
 
G

Guest

Hi.

The double quotes in the DMax( ) function are terminating the string before
intended. Replace them with single quotes. Within your SQL string, try:

DMax('[myField]','myTable')

So that the final SQL string would look something like:

sqlStmt = "SELECT DMax('[myField]','myTable') AS MaxScore FROM myTable;"

(Okay. It's a bad example, but you get the idea.)

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
G

Guest

Good catch!

'69 Camaro said:
Hi.

The double quotes in the DMax( ) function are terminating the string before
intended. Replace them with single quotes. Within your SQL string, try:

DMax('[myField]','myTable')

So that the final SQL string would look something like:

sqlStmt = "SELECT DMax('[myField]','myTable') AS MaxScore FROM myTable;"

(Okay. It's a bad example, but you get the idea.)

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.


Snowsride said:
I have pasted the SQL from a query, that I have tested and runs OK, into a
Docmd.RunSQL statement but I get an error 'Expected: end of statement'.

The problem seems to be associated with a DMax statement which is written
DMax("[myField]","myTable"). The myField text is highlighted when the error
is reported and I suspect I have to add or replace some parentheses. I've
tried all sorts of combinations with no luck.

Any ideas?

Thanks
 
6

'69 Camaro

Oh, I've tripped on this one enough times by doing a quickie copy/paste . .
.. and then I have to go back and fix it. There's never enough time to do it
right the first time, but there's always enough time to do it over. ;-)

Gunny


Klatuu said:
Good catch!

'69 Camaro said:
Hi.

The double quotes in the DMax( ) function are terminating the string
before
intended. Replace them with single quotes. Within your SQL string, try:

DMax('[myField]','myTable')

So that the final SQL string would look something like:

sqlStmt = "SELECT DMax('[myField]','myTable') AS MaxScore FROM
myTable;"

(Okay. It's a bad example, but you get the idea.)

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message
will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the
question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember
that
questions answered the quickest are often from those who have a history
of
rewarding the contributors who have taken the time to answer questions
correctly.


Snowsride said:
I have pasted the SQL from a query, that I have tested and runs OK,
into a
Docmd.RunSQL statement but I get an error 'Expected: end of statement'.

The problem seems to be associated with a DMax statement which is
written
DMax("[myField]","myTable"). The myField text is highlighted when the
error
is reported and I suspect I have to add or replace some parentheses.
I've
tried all sorts of combinations with no luck.

Any ideas?

Thanks
 
D

David C. Holley

Nix that if you putting the SQL statement into a variable the DOUBLE
QUOTES need to be SINGLE QUOTES. If that doesn't help, then post the code.
 

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