Runtime VBA Error 3061: Too Few Parameters. Expected 1.


  • Hi - I have access 2010 database application which did not develop by me. I am doing enhancements for this.When I run my VB code against an Access db, I can a VB Run-time error '3061' which indicates too few parameters. Expected 1.  I am underlined the code where the error occurs(see below). I may found the cause for this error. The query has some parameters and i don't know how to pass those parameters to this.

    Here is the line of code:

    Dim db As Database

    Dim rs As Recordset
    Set db = DBEngine(0)(0)
    Set rs = db.OpenRecordset("qryProdGroupsDetail")

    Kindly help me to resolve this issue.

    Monday, August 06, 2012 10:25 AM


  • While the syntax


    works in Domain Functions (DLookup, DMax, ... ), under DoCmd, under the direct use of the User Interface, and in some other places, it DOES not work under a DAO.Database object, such as CurrentDb, or in the example that you supplied. In your case, you may have to open the querydefinition (querydef), walk trough the parameters collection to assign each of them with a value, then, open the recordset over that querydef.

    Air code:

    Dim qdf as QueryDef
    Dim p AS DAO.Parameter
       Set qdf= QueryDefs("qryProdGroupsDetail")
       For each p in qdf.Parameters
           p.Value = eval(p.Name)   ' assuming the parameter name is  
                                                   ' FORMS!formName!ControlName
       Next p
    Dim rst AS DAO.Recordset
       set rst=qdf.OpenRecordset( )

    Monday, August 06, 2012 10:55 AM