Run Time Error '3075' Syntax error (comma) in Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vasago
    New Member
    • Mar 2014
    • 46

    Run Time Error '3075' Syntax error (comma) in Query

    I have narrowed it down to [Field Trip Selection log].Driver) =" & Me![Employee]. My employees do have a comma in their names. Thank you for your help.


    Error Code says:
    Run-time error '3075'

    Syntax error(comma) in query expression '(((Field Trip Selection log].Driver )= Thomas, Bob)And (([Field Trip Selection Log].[Yes]=False) And (([Field Trip Selection log]/[No] = False))'.




    Code:
    ssql = ssql & "SELECT [Field Trip Selection log].[Pending Bookings ID], [Field Trip Selection log].Driver, [Field Trip Selection log].Note, [Field Trip Selection log].[Log ID], [Field Trip Selection log].[Yes], [Field Trip Selection log].[No] "
    ssql = ssql & "From [Field Trip Selection log] "
    ssql = ssql & "WHERE ((([Field Trip Selection log].Driver) =" & Me![Employee] & ")And (([Field Trip Selection log].[Yes]) = False) And (([Field Trip Selection log].[No]) = False)) "
    ssql = ssql & "ORDER BY [Field Trip Selection log].[Log ID];"
    Set db1 = CurrentDb.OpenRecordset(ssql)
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    Well asked question. Easy to answer :-)

    Your problem here is that SQL expects string literal values (Such as the employee's name.) to be surrounded in quotes ('). That is how it recognises when it's dealing with literal data rather than instructions. More on that at Quotes (') and Double-Quotes (") - Where and When to use them.

    If you're still curious then add this line after your line #4 :
    Code:
    Debug.Print ssql
    When you see the result in the Immediate Pane (Use Ctrl-G to open that.) you should follow through what you see and realise what it's trying to do. If not, and you'd like help interpreting it as SQL would, post the full value in here and we'll help you with it.

    Comment

    Working...