Too few parameters error MS Access SQL

∥☆過路亽.° 提交于 2019-12-11 02:43:32

问题


I'm getting a run-time error: too few parameters: expected 2.

This code is supposed to get the next employee in line for assignments. The employees [programs] and [Language] have to match the [program] and [language] in the table CFRRR.

strSQL = "SELECT TOP 1 WorkerID FROM attendance WHERE [Programs] LIKE '*" & program & "*' AND [Language] = '" & Language & "' AND [Status] = " & ("Available") & " ORDER BY TS ASC"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

Here's what Debug.Print strSQL shows me:

SELECT TOP 1 WorkerID FROM attendance WHERE [Programs] LIKE '*program*' AND [Language] LIKE '*Language*' AND [Status] = Available ORDER BY TS ASC


回答1:


Assuming you want [Status] to match the word Available, add quotes as Mark suggested ...

SELECT TOP 1 WorkerID FROM attendance
WHERE [Programs] LIKE '*program*' AND [Language] LIKE '*Language*' AND [Status] = 'Available'
ORDER BY TS ASC

However that still leaves one "parameter" unaccounted for. Create a new query in the Access query designer. Switch to SQL View and paste in your statement text.

When you try to run that query, Access will pop up an input dialog asking you to supply a value for the parameter. That dialog also includes the word which Access assumes to be the parameter.

Compare that word with your SQL statement. It is generally a misspelled object (field or table) name, function, or SQL keyword. In this case, I can't spot function or keyword errors, so will guess the problem is a field or table name.



来源:https://stackoverflow.com/questions/30142827/too-few-parameters-error-ms-access-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!