Solved

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

Posted on 2008-10-30
6
1,440 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

19 Experts available now in Live!

Get 1:1 Help Now