Link to home
Start Free TrialLog in
Avatar of Uncochen
Uncochen

asked on

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

[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

Avatar of numberkruncher
numberkruncher
Flag of United Kingdom of Great Britain and Northern Ireland image

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

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

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

Avatar of Jeffrey Coachman
Uncochen,

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

JeffCoachman
Avatar of Uncochen
Uncochen

ASKER

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!!
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial