I'm getting a run-time error: too few parameters: expected 2.
我遇到了运行时错误:参数太少:预期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.
这段代码应该让下一个员工排成一行。员工[程序]和[语言]必须匹配表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:
这是Debug.Print strSQL向我展示的内容:
SELECT TOP 1 WorkerID FROM attendance WHERE [Programs] LIKE '*program*' AND [Language] LIKE '*Language*' AND [Status] = Available ORDER BY TS ASC
SELECT TOP 1 WORKID FROM出席WHERE [程序] LIKE'*程序*'和[语言] LIKE'*语言*'和[状态] =可用ORDER BY TS ASC
1 个解决方案
#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.
然而,这仍然留下一个“参数”下落不明。在Access查询设计器中创建一个新查询。切换到SQL视图并粘贴到语句文本中。
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.
当您尝试运行该查询时,Access将弹出一个输入对话框,要求您为该参数提供值。该对话框还包括Access假定为参数的单词。
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.
将该单词与您的SQL语句进行比较。它通常是拼写错误的对象(字段或表)名称,函数或SQL关键字。在这种情况下,我无法发现函数或关键字错误,因此会猜测问题是字段或表名称。
#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.
然而,这仍然留下一个“参数”下落不明。在Access查询设计器中创建一个新查询。切换到SQL视图并粘贴到语句文本中。
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.
当您尝试运行该查询时,Access将弹出一个输入对话框,要求您为该参数提供值。该对话框还包括Access假定为参数的单词。
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.
将该单词与您的SQL语句进行比较。它通常是拼写错误的对象(字段或表)名称,函数或SQL关键字。在这种情况下,我无法发现函数或关键字错误,因此会猜测问题是字段或表名称。