问题
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