Solved

Runtime error '3061': Too few Parameters. Expected 3

Posted on 2008-10-30
6
1,461 Views
Last Modified: 2013-11-27
[qryEditNewSummary] is a Query, If change the [qryEditNewSummary] to a "Table" , It work ok, no error. but if change to any Query, it will have runtime error 3601.
I have check the query name, and field name, everything is ok.

What 's wrong with query in dao??
Private Sub cmdRandom_Click()   

 Dim dbs As Database

    Dim rst As Recordset

        Set dbs = CurrentDb

        strSQL = "Select Total From [qryEditNewSummary]"

        Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

    MsgBox rst!Total

End Sub

Open in new window

0
Comment
Question by:Uncochen
6 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22846854
Have you tried the following:
Private Sub cmdRandom_Click()   

 Dim dbs As Database

    Dim rst As Recordset

        Set dbs = CurrentDb

' Without square brackets around qryEditNewSummary

        strSQL = "Select Total From qryEditNewSummary"

        Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

    MsgBox rst!Total

End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22846858
In fact you probably also need to specify where 'Total' comes from.
Private Sub cmdRandom_Click()   

 Dim dbs As Database

    Dim rst As Recordset

        Set dbs = CurrentDb

        strSQL = "Select qryEditNewSummary.Total From qryEditNewSummary"

        Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)

    MsgBox rst!Total

End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22846884
This error can also occur when the query requires additional input parameters. I believe that you can specify those using something like the following:
dbs.Parameters![SpecialParm] = "SomeValue"

dbs.Parameters![AnotherParm] = "SomeValue"

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22848024
Uncochen,

Can you post the SQL for:
qryEditNewSummary
... so we don't have to guess at what the problem is?

JeffCoachman
0
 

Author Comment

by:Uncochen
ID: 22849182
I try to  make a new access file and run, it work Ok!!!
the ado and query no this problem. I don't kown what reason the old file will happen the problem??? I did try to greate a new query in the old file, still problem!!
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 22849454
Like Jeff suggested, the problem may be in qryEditNewSummary.

A very common cause of this error is Form References in a query.

For example, if your query looks like this:
SELECT *
FROM YourTable
WHERE YourField = Forms!YourForm!YourTextboxName

This query will work perfectly when run from the database window. However, the reference to the form control will cause the "Too Few Parameters" Error if that same query is called from VBA.


To resolve this, all form references must be evaluated seperately from the query.
 
To help you further with this, we would need to see the SQL for  qryEditNewSummary.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now