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:30

My problem turned out to be, I had altered a table to add a column called Char. As this is a reserved word in MS Access it needed square brakcets (Single or double quote are no good) in order for the alter statement to work before I could then update the newly created column.

查看更多
老娘就宠你
3楼-- · 2019-01-09 15:32

Make sure [qry_all_details] exists and is runnable. I suspect it or any query it uses, is missing the parameter.

查看更多
男人必须洒脱
4楼-- · 2019-01-09 15:35

Does the query has more than the parameter siteID, becouse if you want to run the query one parameter still isn't filled witch gives you the error

查看更多
不美不萌又怎样
5楼-- · 2019-01-09 15:36

(For those who read all answers). My case was simply the fact that I created a SQL expression using the format Forms!Table!Control. That format is Ok within a query, but DAO doesn't recognize it. I'm surprised that nobody commented this.

This doesn't work:

Dim rs As DAO.Recordset, strSQL As String
strSQL = "SELECT * FROM Table1 WHERE Name = Forms!Table!Control;"
Set rs = CurrentDb.OpenRecordset(strSQL)

This is Ok:

Dim rs As DAO.Recordset, strSQL, val As String
val = Forms!Table!Control
strSQL = "SELECT * FROM Table1 WHERE Name = '" & val & "';"
Set rs = CurrentDb.OpenRecordset(strSQL)
查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-09 15:41

My problem was also solved by the Single Quotes around the variable name

查看更多
登录 后发表回答