Run-time error '3061'. Too few parameters.

2019-01-09 14:58发布

I have the following 'set recordset' line that I cannot get working. The parameters seem correct according to all available help I can find on the subject.

The error displays :

"Run-time error '3061'. Too few parameters. Expected 1."

Here is the line of code:

Set rs = dbs.OpenRecordset("SELECT Centre_X, Centre_Y FROM [qry_all_details] 
WHERE ID = " & siteID & ";", dbOpenSnapshot)

Where rs is the recordset (Dim rs As Recordset) and dbs = CurrentDb()

Any help would be appreciated.

I have tried removing the WHERE cause with no effect, and also using single quotes between double quotes, but no joy.

Many thanks.

标签: ms-access vba
11条回答
闹够了就滚
2楼-- · 2019-01-09 15:16

I got the same error with something like:

Set rs = dbs.OpenRecordset _
( _
  "SELECT Field1, Field2, FieldN " _
  & "FROM Query1 " _
  & "WHERE Query2.Field1 = """ & Value1 & """;" _
, dbOpenSnapshot _
)

I fixed the error by replacing "Query1" with "Query2"

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-09 15:18

you have:

WHERE ID = " & siteID & ";", dbOpenSnapshot)

you need:

WHERE ID = "'" & siteID & "';", dbOpenSnapshot)

Note the extra quotations ('). . . this kills me everytime

Edit: added missing double quote

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-09 15:19

In my case, I got this error when I tried to use in a query a new column, which I added to MySQL table (linked to MS Access), but didn't refresh it inside MS Access.

To refresh a linked remote table:

  1. Open "Linked Table Manager" ("External Data" tab on ribbon);
  2. Select a checkbox near the table you want to refresh;
  3. Press "OK" button.
查看更多
对你真心纯属浪费
5楼-- · 2019-01-09 15:20

In my case, I had simply changed the way I created a table and inadvertently changed the field name I tried to query. Make sure the field names you reference in the query actually exist in the table/query you are querying.

查看更多
混吃等死
6楼-- · 2019-01-09 15:26

"Run-time error '3061'. Too few parameters. Expected 1."

I believe this happens when the field name(s) in your sql query do not match the table field name(s), i.e. a field name in the query is wrong or perhaps the table is missing the field altogether.

查看更多
冷血范
7楼-- · 2019-01-09 15:28

I got the same error message before. in my case, it was caused by type casting. check if siteID is a string, if it is you must add simple quotes.

hope it will help you.

查看更多
登录 后发表回答