All
Hereby a simplified example of my problem.
I created a form with a combobox and a regular Access Query with next SQL-code
If frmMain is open and you select an item from cboItem, query above runs fine if you double click it.
However, I also have a button on my form to run some VB-code where this query has to be used. So the code contains
When the VBA-code tries to open the recordset, it results in error "Run time error 3061: too few parameters. Expected 1".
I guess this is somehow caused as the VBA-code takes the SQL-string literally and it does not replace [forms]![frmmain]![cboItem])) into the real value on the form.
How can I solve this? Important notice: I must use the Access query as base. I do know I could solve this by using something like below, but this is no option. The recordset must use "qrySelectedItem"
Does somebody knows a solution?
Hereby a simplified example of my problem.
I created a form with a combobox and a regular Access Query with next SQL-code
Code:
SELECT tblItems.Item, tblItems.Cost, tblItems.ID
FROM tblItems
WHERE (((tblItems.ID)=[forms]![frmmain]![cboItem]));
If frmMain is open and you select an item from cboItem, query above runs fine if you double click it.
However, I also have a button on my form to run some VB-code where this query has to be used. So the code contains
Code:
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("qrySelectedItem")
When the VBA-code tries to open the recordset, it results in error "Run time error 3061: too few parameters. Expected 1".
I guess this is somehow caused as the VBA-code takes the SQL-string literally and it does not replace [forms]![frmmain]![cboItem])) into the real value on the form.
How can I solve this? Important notice: I must use the Access query as base. I do know I could solve this by using something like below, but this is no option. The recordset must use "qrySelectedItem"
Code:
strSQL="select * from tblItems where [ID]=" & me.cboItem
set rs = CurrentDB.OpenRecordset(strSQL)
Does somebody knows a solution?