Error opening query recordset that references control object
I have a several saved queries that are hierarchically dependent. In one of my forms I need to access one of the queries.
Set rs = db.OpenRecordset("qryCTI_Unbilled")
But I get an error:
Run-time error '3601': Too few parameters. Expected 2.
The strange thing about this is, if I open the query directly, it has all the information I need, and I get no errors.
What seems to be causing the problem is in the WHERE clause where I reference a textbox from the form.
...WHERE (((ars5_budgets1.DATE_FROM)<=[Forms]![frmCTI]![txtBillDateEnd]) ...
This is referenced in the a query at the base of the nested structure.
Is this doable? Based on the debug, I am thinking that in runtime mode, the query is not able to pick up these control object values to process the query, because in debug mode, when the error pops up, I get no records when I open the query.
I guess an alternative would be to write the entire SQL statement as a string and assign the object values to VBA variable. Doing this at runtime may effect performance because of the complexity, but at least that's a solution.
Any alternative solution is appreciated, thanks!
I have a several saved queries that are hierarchically dependent. In one of my forms I need to access one of the queries.
Set rs = db.OpenRecordset("qryCTI_Unbilled")
But I get an error:
Run-time error '3601': Too few parameters. Expected 2.
The strange thing about this is, if I open the query directly, it has all the information I need, and I get no errors.
What seems to be causing the problem is in the WHERE clause where I reference a textbox from the form.
...WHERE (((ars5_budgets1.DATE_FROM)<=[Forms]![frmCTI]![txtBillDateEnd]) ...
This is referenced in the a query at the base of the nested structure.
Is this doable? Based on the debug, I am thinking that in runtime mode, the query is not able to pick up these control object values to process the query, because in debug mode, when the error pops up, I get no records when I open the query.
I guess an alternative would be to write the entire SQL statement as a string and assign the object values to VBA variable. Doing this at runtime may effect performance because of the complexity, but at least that's a solution.
Any alternative solution is appreciated, thanks!
Last edited: