Error 3061: Too Few Parameters. Expected 2

because apparently you cant use form variables in recordsets.

by adding the same value into the query, you avoided this.
 
In my case the problem was that I added the wrong field in my query that the paramater is based on. The parameter ([Forms]![Form1]![idBplanApplication]) I did not add in my query but as a filter for my recordset. By adding the correct fieldname (BPlanApplication.idBplanApplication from my main table) in my query, the error message ("Item not found in this collection") disappeared.
 
Here is a DAO example of how to pass parameters when you execute a query in code. I don't know how to do this with ADO but ADO does not have a parameters collection so the method would be different.

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qryQCMainSizeCheck
qd.Parameters![YourParm1] = "SomeValue"
qd.Parameters![YourParm2] = "SomeValue"
Set rst = qd.OpenRecordset

If you are only going to execute this query from code I would change the parm names which I gather are now in the form -
Forms!YourFormName!YourControl. You would replace [YourParm1] with whatever the form field reference is -
qd.Parameters![Forms]![YourForm]![YourControl] = [Forms]![YourForm]![YourControl]


Hello!!

above code worked for me!!
I just had to put parameters in the following way!!

QDF As QueryDef

Set MYDA = CurrentDb

Set QDF = MYDA.QueryDefs!RecibosS
QDF.Parameters(0).Value = [Forms]![ImpExp]![Cuadrocombinado11]
QDF.Parameters(1).Value = [Forms]![ImpExp]![Combo112]
Set Tbla = QDF.OpenRecordset

I Hope this helps...

Cheers :)
 

Users who are viewing this thread

Back
Top Bottom