?
Solved

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

Posted on 2008-10-30
6
Medium Priority
?
1,578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

 
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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…
Suggested Courses

764 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