Syntax Error Message in Query statement 
Author Message
 Syntax Error Message in Query statement

Visual Basic 6
Access 2000

I am tring to execute the following SQL statement and getting this syntax
error.  I receive the following message:

Run-time error '-2147217900(80040e14)'
Syntax Error (Missing operator) in query expression

Here is my code:

strSQL = "Select MAX[ID_NUMBER] from READERS"

    With rsReaderID
       .CursorLocation = adUseClient
       .Open strSQL, conUREAD1, , , adCmdText
        strIDNumber = ![ID_NUMBER]
    End With

Can someone please point out exactly what is missing.  I checked a number of
places but can't see a definitive solution.

Thanks



Sat, 30 Jul 2005 23:36:27 GMT  
 Syntax Error Message in Query statement

Quote:
> Visual Basic 6
> Access 2000

> I am tring to execute the following SQL statement and getting this syntax
> error.  I receive the following message:

> Run-time error '-2147217900(80040e14)'
> Syntax Error (Missing operator) in query expression

> Here is my code:

> strSQL = "Select MAX[ID_NUMBER] from READERS"

>     With rsReaderID
>        .CursorLocation = adUseClient
>        .Open strSQL, conUREAD1, , , adCmdText
>         strIDNumber = ![ID_NUMBER]
>     End With

> Can someone please point out exactly what is missing.  I checked a number
of
> places but can't see a definitive solution.

> Thanks

I think the problem is you are using [] instead of () in the MAX, so it
should be

strSQL = "Select MAX(ID_NUMBER) from READERS"

Quote:
>         strIDNumber = ![ID_NUMBER]

Never seen this syntax before.  Normally:

strIdNumber = .fields (0)

Notice I have specified the field using an index number as I don't think you
can guarantee what name the database will give the retrieved column unless
you specify it in your query, e.g.:

strSQL = "Select MAX(ID_NUMBER) as max_id from READERS"

In which case you could:

strIdNumber = .fields ("max_id")

--
John Blessing
http://www.LbeHelpdesk.com - Help Desk software at affordable prices
http://www.free-helpdesk.com - Completely free help desk software !
http://www.lbetoolbox.com - Remove Duplicates from MS Outlook
http://www.lbesync.com - Synchronize two Outlook Personal Folders



Sat, 30 Jul 2005 23:52:10 GMT  
 Syntax Error Message in Query statement
Hi there,

John Blessing.....you are a blessing (no pun intended).  That did the trick.
Thank you very much for your help!!!


Quote:


> > Visual Basic 6
> > Access 2000

> > I am tring to execute the following SQL statement and getting this
syntax
> > error.  I receive the following message:

> > Run-time error '-2147217900(80040e14)'
> > Syntax Error (Missing operator) in query expression

> > Here is my code:

> > strSQL = "Select MAX[ID_NUMBER] from READERS"

> >     With rsReaderID
> >        .CursorLocation = adUseClient
> >        .Open strSQL, conUREAD1, , , adCmdText
> >         strIDNumber = ![ID_NUMBER]
> >     End With

> > Can someone please point out exactly what is missing.  I checked a
number
> of
> > places but can't see a definitive solution.

> > Thanks

> I think the problem is you are using [] instead of () in the MAX, so it
> should be

> strSQL = "Select MAX(ID_NUMBER) from READERS"

> >         strIDNumber = ![ID_NUMBER]

> Never seen this syntax before.  Normally:

> strIdNumber = .fields (0)

> Notice I have specified the field using an index number as I don't think
you
> can guarantee what name the database will give the retrieved column unless
> you specify it in your query, e.g.:

> strSQL = "Select MAX(ID_NUMBER) as max_id from READERS"

> In which case you could:

> strIdNumber = .fields ("max_id")

> --
> John Blessing
> http://www.LbeHelpdesk.com - Help Desk software at affordable prices
> http://www.free-helpdesk.com - Completely free help desk software !
> http://www.lbetoolbox.com - Remove Duplicates from MS Outlook
> http://www.lbesync.com - Synchronize two Outlook Personal Folders



Sun, 31 Jul 2005 00:08:07 GMT  
 Syntax Error Message in Query statement
And to tell you why: ;-)

You're selecting an SQL function "MAX()", not
any column in the table. so the returned recordset
contains 1 row, containing 1 unnamed coloumn with
index 0.

If you want to use the syntax you tried, try naming
the result of the function like this:

  strSQL = "SELECT MAX(Id_Number) AS Max_Id FROM Readers"

  rsReaderID.CursorLocation = adUseClient
  rsReaderID.Open strSQL, conUREAD1, , , adCmdText

  If Not rsReaderID.Eof Then
    strIDNumber = rsReaderID.("Max_Id")
  Else
    'Something went wrong obtaining the max-id...
  End If

--
Dag.


Quote:
> Hi there,

> John Blessing.....you are a blessing (no pun intended).  That did the
trick.
> Thank you very much for your help!!!





> > > Visual Basic 6
> > > Access 2000

> > > I am tring to execute the following SQL statement and getting this
> syntax
> > > error.  I receive the following message:

> > > Run-time error '-2147217900(80040e14)'
> > > Syntax Error (Missing operator) in query expression

> > > Here is my code:

> > > strSQL = "Select MAX[ID_NUMBER] from READERS"

> > >     With rsReaderID
> > >        .CursorLocation = adUseClient
> > >        .Open strSQL, conUREAD1, , , adCmdText
> > >         strIDNumber = ![ID_NUMBER]
> > >     End With

> > > Can someone please point out exactly what is missing.  I checked a
> number
> > of
> > > places but can't see a definitive solution.

> > > Thanks

> > I think the problem is you are using [] instead of () in the MAX, so it
> > should be

> > strSQL = "Select MAX(ID_NUMBER) from READERS"

> > >         strIDNumber = ![ID_NUMBER]

> > Never seen this syntax before.  Normally:

> > strIdNumber = .fields (0)

> > Notice I have specified the field using an index number as I don't think
> you
> > can guarantee what name the database will give the retrieved column
unless
> > you specify it in your query, e.g.:

> > strSQL = "Select MAX(ID_NUMBER) as max_id from READERS"

> > In which case you could:

> > strIdNumber = .fields ("max_id")

> > --
> > John Blessing
> > http://www.LbeHelpdesk.com - Help Desk software at affordable prices
> > http://www.free-helpdesk.com - Completely free help desk software !
> > http://www.lbetoolbox.com - Remove Duplicates from MS Outlook
> > http://www.lbesync.com - Synchronize two Outlook Personal Folders



Sun, 31 Jul 2005 02:15:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. -2147217900 Error: Syntax error in INSERT INTO statement

2. Syntax Error in SQL statement

3. Syntax error in Update statement (with a date)

4. vbscript syntax error - expected end of statement

5. Syntax Error in Update Statement.

6. Syntax error in UPDATE statement

7. As Statement Syntax Error

8. Syntax error in SQL statement

9. Syntax error in INSERT INTO statement

10. ASP Syntax error in UPDATE statement.

11. Syntax error in UPDATE statement

12. Syntax error in INSERT statement

 

 
Powered by phpBB® Forum Software