I am trying to get a parameter query working so I can gather field data using VBA.
I have a query (Qry_TotalOrderPrice) that uses one table and is as follows:
Field1=Order_ID
Criteria=[Forms]![Frm_Orders]![Order_ID] (form reference is valid)
Field2=Total of two fields using the SUM function
I am then using the following code in VBA to access this query but I keep on getting 'Too few parameters. Expected 1':
***
Sub CalculateTotalCost()
Dim db As Database
Dim rst As Recordset
Dim qry As QueryDef
Set db = DBEngine(0).Databases(0)
Set qry = db.QueryDefs("Qry_TotalOrderPrice")
qry![Forms!Frm_Orders!Order_ID] = [Forms]![Frm_Orders]![Order_ID]
Set rst = db.OpenRecordset("Qry_TotalOrderPrice")
End Sub
***
I did try a more simpler way which was to make the query a normal one (by removing all querydef references in VBA) then opening query via the openrecordset method but even then I get a 'type mismatch' error.
At the moment I`m using a hidden subform to get thi data (so it doesn't spoil the current look of the main form I`m using) but I would like to resolve this problem using a simpler method.
Any help appreciated
Derek
I have a query (Qry_TotalOrderPrice) that uses one table and is as follows:
Field1=Order_ID
Criteria=[Forms]![Frm_Orders]![Order_ID] (form reference is valid)
Field2=Total of two fields using the SUM function
I am then using the following code in VBA to access this query but I keep on getting 'Too few parameters. Expected 1':
***
Sub CalculateTotalCost()
Dim db As Database
Dim rst As Recordset
Dim qry As QueryDef
Set db = DBEngine(0).Databases(0)
Set qry = db.QueryDefs("Qry_TotalOrderPrice")
qry![Forms!Frm_Orders!Order_ID] = [Forms]![Frm_Orders]![Order_ID]
Set rst = db.OpenRecordset("Qry_TotalOrderPrice")
End Sub
***
I did try a more simpler way which was to make the query a normal one (by removing all querydef references in VBA) then opening query via the openrecordset method but even then I get a 'type mismatch' error.
At the moment I`m using a hidden subform to get thi data (so it doesn't spoil the current look of the main form I`m using) but I would like to resolve this problem using a simpler method.
Any help appreciated
Derek