View Full Version : Syntax error (comma) in query expression
09-10-2007, 11:10 PM
Hello all. I have an error that has just showed up. The error is as follows:
Microsoft JET Database Engine error '80040e14'
Syntax error (comma) in query expression 'id = 1,382'.
/Timesheet/EQ_EditTime.asp, line 26
Here is the query:
SELECT * FROM tblEqMilesHours WHERE id = " & RecId & "
... and I think that it has something to do with the 'id' being a four digit number. In the database it is set up as an autonumber. What do I need to do to get rid of this error?
09-10-2007, 11:45 PM
Make sure that you have a cInt(RecID) and that should help remove this error.
The problem is that you are trying to look at data with a COMMA in it, and Access doesn't recognize it.
"SELECT * FROM tblEqMilesHours WHERE id = " & cInt(RecID) & ";"
09-11-2007, 12:37 AM
Thank you so much. That worked perfectly. I got it working by changing the variable to a string, but I feel your way is more correct.
02-23-2011, 08:04 AM
syntex error (comma) in query?
I have no idea whay I get this error.
I have warehouse as text, I am using a list box to get my WHs, from the list I get WH In (("381","320)) which makes sence but i get the syntex error (comma) in query expenssion error
Me.Visible = False
Dim i As Integer
Dim str As String
Dim strSQL As String
Dim qdef As DAO.QueryDef
Dim MyDB As DAO.Database
Dim strWhere As String
Dim strIN As String
Dim flgSelectAll As Boolean
Dim varItem As Variant
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "qry_FINALAvailablePhysical-Stock"
'Build the IN string by looping through the listbox
For i = 0 To List7.ListCount - 1
If List7.Selected(i) Then
If List7.Column(0, i) = "All" Then
flgSelectAll = True
strIN = strIN & List7.Column(0, i) & """" & "," & """"
'Create the WHERE string, and strip off the last comma of the IN string
str = "(""" & Left(strIN, Len(strIN) - 2) & ")"
'If "All" was selected in the listbox, don't add the WHERE condition
If flgSelectAll Then
DoCmd.OpenReport stDocName, acPreview
'Clear listbox selection after running query
For Each varItem In Me.List7.ItemsSelected
Me.List7.Selected(varItem) = False
strSQL = " WH In ( " & str & " )"
DoCmd.OpenReport stDocName, acPreview, , strSQL
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.