Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run-time error '3061'. Too few parameters. Expected 1. (Access 2007)

Tags:

vba

ms-access

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.

like image 968
uk52rob Avatar asked Mar 26 '11 20:03

uk52rob


3 Answers

"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.

like image 162
david Avatar answered Nov 09 '22 22:11

david


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

like image 13
DATS Avatar answered Nov 09 '22 22:11

DATS


(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)
like image 10
John Doe Avatar answered Nov 09 '22 21:11

John Doe