Error 3061 Too few parameters.....

E

Eusi

I have the following code connected to a command button:

Dim al As Double

Let al = 0

Dim dbs As Database, rst As Recordset
Dim strSQL As String


Set dbs = CurrentDb
strSQL = "SELECT [e2a as 2].[AppRef], [e2a as 2].
[need1], [e2a as 2].status " _
& "FROM [e2a as 2] " _
& "WHERE ((([e2a as 2].[need1])='n1'));"

Set rst = dbs.OpenRecordset(strSQL)
rst.MoveLast
Let al = rst.RecordCount
rst.Close
Set dbs = Nothing

MsgBox al


when execution gets to the "set rst.." line, the error
"Run-time error 3061. Too few parameters. Expected 2."
appears. I've checked the knowledge base but can't seem
to find the exact solution.

[e2a as 2] is a query
[need1] is the product of a function
[status] is the product of a function

Any ideas on how to sort this one out?

Thanks in advance!

Eusi
 
J

John Viescas

The database engine thinks you're referencing something that looks like a
field name that is not in any table in the FROM clause. What happens if you
paste this SQL into a new query SQL view and try to look at the datasheet?
If you get prompted for a parameter, that will help you identify the
problem.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
 
E

Eusi

I tried what you suggested and the query worked however
it won't work via the visual basic route.

Any more ideas anyone?

Thanks
-----Original Message-----
The database engine thinks you're referencing something that looks like a
field name that is not in any table in the FROM clause. What happens if you
paste this SQL into a new query SQL view and try to look at the datasheet?
If you get prompted for a parameter, that will help you identify the
problem.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR? pg=personal&fr_id=1090&px=1434411
Eusi said:
I have the following code connected to a command button:

Dim al As Double

Let al = 0

Dim dbs As Database, rst As Recordset
Dim strSQL As String


Set dbs = CurrentDb
strSQL = "SELECT [e2a as 2].[AppRef], [e2a as 2].
[need1], [e2a as 2].status " _
& "FROM [e2a as 2] " _
& "WHERE ((([e2a as 2].[need1])='n1'));"

Set rst = dbs.OpenRecordset(strSQL)
rst.MoveLast
Let al = rst.RecordCount
rst.Close
Set dbs = Nothing

MsgBox al


when execution gets to the "set rst.." line, the error
"Run-time error 3061. Too few parameters. Expected 2."
appears. I've checked the knowledge base but can't seem
to find the exact solution.

[e2a as 2] is a query
[need1] is the product of a function
[status] is the product of a function

Any ideas on how to sort this one out?

Thanks in advance!

Eusi


.
 
V

Van T. Dinh

If you have reference to, says, a Control on a Form in the Query, you need
to resolve the reference before passing the SQL String to JET since JET
doesn't know about the Control on the Form.

The same Query works fine in the QBE GUI since in this case the Expression
Service steps in and resole the reference before passing the SQL String to
JET for execution.
 
J

John Viescas

See also Van's reply...

If the query depends on a form being open, you must resolve that in the
query before you can open it in code. When you tested the query, was the
query the only thing open in your database? What's the SQL of the [e2a as
2] query?

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR?pg=personal&fr_id=1090&px=1434411
Eusi said:
I tried what you suggested and the query worked however
it won't work via the visual basic route.

Any more ideas anyone?

Thanks
-----Original Message-----
The database engine thinks you're referencing something that looks like a
field name that is not in any table in the FROM clause. What happens if you
paste this SQL into a new query SQL view and try to look at the datasheet?
If you get prompted for a parameter, that will help you identify the
problem.

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out"
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
http://www.deanforamerica.com/site/TR? pg=personal&fr_id=1090&px=1434411
Eusi said:
I have the following code connected to a command button:

Dim al As Double

Let al = 0

Dim dbs As Database, rst As Recordset
Dim strSQL As String


Set dbs = CurrentDb
strSQL = "SELECT [e2a as 2].[AppRef], [e2a as 2].
[need1], [e2a as 2].status " _
& "FROM [e2a as 2] " _
& "WHERE ((([e2a as 2].[need1])='n1'));"

Set rst = dbs.OpenRecordset(strSQL)
rst.MoveLast
Let al = rst.RecordCount
rst.Close
Set dbs = Nothing

MsgBox al


when execution gets to the "set rst.." line, the error
"Run-time error 3061. Too few parameters. Expected 2."
appears. I've checked the knowledge base but can't seem
to find the exact solution.

[e2a as 2] is a query
[need1] is the product of a function
[status] is the product of a function

Any ideas on how to sort this one out?

Thanks in advance!

Eusi


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top