请帮我调试我的SQL查询!

时间:2010-10-25 17:16:49

标签: sql debugging ms-access

我继续收到错误“关键字'附近的语法不正确',其中'。”

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)"

1 个答案:

答案 0 :(得分:3)

将查询分配给字符串:

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

在最后一行放置一个断点,然后将查询复制/粘贴到MS Access查询视图中。尝试运行它,MS Access会告诉你到底出了什么问题。