View Full Version : Syntax error (comma) in query expression

Sep 10th, 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?



Sep 10th, 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) & ";"

Sep 11th, 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.

Thanks again,


Feb 23rd, 2011, 08:04 AM
Your Question
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
End If
strIN = strIN & List7.Column(0, i) & """" & "," & """"

End If
Next 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
End If

'Clear listbox selection after running query
For Each varItem In Me.List7.ItemsSelected
Me.List7.Selected(varItem) = False
Next varItem

strSQL = " WH In ( " & str & " )"

DoCmd.OpenReport stDocName, acPreview, , strSQL