Question : too few parameters. expected 2

Hi

I have queries setup in access that are using query by form i.e parameters passed via text boxes - the queries work fine when running within access. I am trying to connect an excel workbook and its pivottable to this query but during the wizard i get the error~: "too few parameters. expected 2" is this a limitation or can i somehow get around this.

Thanks

Answer : too few parameters. expected 2


<<"too few parameters. expected 2">>

it's not a limitation.  When you open a query in code, Access leaves everything up to you. That includes resolving any references. Fortunately, there is an easy way around that:

Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset


Set db = CurrentDb()
Set qdef = db.QueryDefs(source)
qdef.Parameters(0) = Eval(qdef.Parameters(0).Name)
Set rs = qdef.OpenRecordset()


Since the parameter name is a reference to the form and control, using Eval() gets the value for you. If you had multiple parameters, then you would just loop on the parameters collection doing a Eval() for each.

JimD.

Random Solutions  
 
programming4us programming4us