Solved

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

Posted on 2008-10-30
6
1,484 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert null in sql server 12 34
update all email addresses SQL 1 24
SQL Group on First occurrence 9 25
Awk & Pythagoras - applying csv file data to the problem 10 10
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

810 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