views:

39

answers:

1

I keep on getting the error "incorrect syntax near keyword 'where'."

DoCmd.RunSQL "insert into userPreferences (userId, GroupId, preferenceId, properties, isDefault)" & _
        "select " + Me.UserId + ", " + Me.GroupId + ", preferenceid, properties, 1 from preferences " & _
        " where preferenceId not in " & _
        "(select preferenceId from userPreferences where GroupId = " + Me.GroupId + _
        " and userId = " + Me.UserId + _
        " ) and preferenceid not in " & _
        "(select preferenceid from GroupPreferences " & _
        "where cabGroupId = " + Me.GroupId + " and override = 0)"
+3  A: 

Assign the query to a string:

Dim myQuery as String
Set myQuery = "insert ..."
DoCmd.RunSql myQuery

Place a breakpoint on the last line, and copy/paste the query into MS Access query view. Try to run it and MS Access will tell you exactly what's wrong.

Andomar
dmr
@dmr: Hah, missed that on first read. The debug method should help in most cases though, Access query view is an excellent place to learn SQL
Andomar