19
votes

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.

14
Is this query you're opening a parameterized one? Maybe it's expecting a value...Tim Williams
Not sure if it's worth noting but your "one line" of code, at least as you entered it, is occupying two lines. Is that correct or is just the formatting here at SO?Oneide

14 Answers

54
votes

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

12
votes

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

7
votes

(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)
5
votes

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

2
votes

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.

1
votes

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

1
votes

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.

1
votes

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"

0
votes

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

0
votes

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.
0
votes

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.

0
votes

This Message is also possible to pop up, if there is a typo in the fields on which you define a join

0
votes

Thanks for John Doe's solution that helped a lot. Mine is very similar with some difference, using TempVars

Instead of :

      strSQL = "SELECT * FROM Table1 WHERE Name = Forms!Table!Control;"

I used:

      strSQL = "SELECT * FROM Query1"  , Query1 being common for other usage

Query1 as:

 "Select Field1, Field2 from Table1 where Id= [TempVars]![MyVar]

And similarly, removing [TempVars]![MyVar] from view solved the problem.

-1
votes

In My case I had an INSERT INTO TableA (_ ,_ ,_) SELECT _ ,_ ,_ from TableB, a run-time error of 33061 was a field error. As @david mentioned. Either it was a field error: what I wrote in SQL statement as a column name did not match the column names in the actual access tables, for TableA or TableB.

I also have an error like @DATS but it was a run-time error 3464.