Parameter Query

A_Li_N

New member
Local time
Today, 03:56
Joined
Nov 19, 2008
Messages
4
I have a query that is based off of quite a few other queries, one of which takes 2 parameters that are linked to a form's fields. If I open the query directly, it works fine and doesn't ask for the parameters (if the form is open of course). But if I try to set a recordset to this query, even with the form open, it says it wants 2 parameters.

Is there a way to get around this or make it work (a correct way...I've found a work around involving setting the form's recordsource to the query and then taking setting the recordset to the form's recordsetclone)? Or should I be going to the direct data and doing calculations from the beginning all in the VBA code? (The query takes raw time data of a timeclock, calculates the rounded time and gives the lengths in hours for the payroll)
 
Have you tried defining the parameters explicitly in the query - not just adding the form references to the criteria row, but also setting them in the Parameters list?
 
When you open a query with paramaters as a recordset you need to do this

Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset

Set qdf = DBEngine(0)(0).QueryDefs("YourQueryName")
qdf("[Forms]![frmOutput]![ParamaterOne]") = getthevalue1
qdf("[Forms]![frmOutput]![ParamaterTwo]") = getthevalue2

Set rs = qdf.OpenRecordset

You will need to get the value that would have been in the form, the form doesn't need to be open.
 
When you open a query with paramaters as a recordset you need to do this

Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset

Set qdf = DBEngine(0)(0).QueryDefs("YourQueryName")
qdf("[Forms]![frmOutput]![ParamaterOne]") = getthevalue1
qdf("[Forms]![frmOutput]![ParamaterTwo]") = getthevalue2

Set rs = qdf.OpenRecordset

You will need to get the value that would have been in the form, the form doesn't need to be open.

I went with this solution and it worked. I was under the impression that linking parameters to form fields would make it so you didn't need to 'provide' the values, but I guess I was wrong when it comes to VBA?

Thanks for the reply!
 

Users who are viewing this thread

Back
Top Bottom