Want to set parameter in code for recordsource

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have a subform, and the RecordSource of the subform is
a query that contains a parameter. I am prompted to
enter the value of the parameter every time I navigate to
a different record in the parent form. However, I want
to set the parameter's value in code, avoiding manual
entry.

I need to set the parameter value, and requery the
subform, every time the parent form navigates to a new
record. Can this be done in code? The value of the
parameter is a field that is available in the parent form.

The link master/link child properties don't solve my
problem because the recordsource of the subform is a
union query, and performance is unacceptable when I rely
on link master/link child properties. The root cause of
this performance probelm is illustrated by the following
two queries. They are equivalent, but the first one
executes MUCH faster:

Select * From Q1 Where Fld = value_1 UNION
Select * From Q2 Where Fld = value_1


Select * From
(Select * From Q1 UNION Select * From Q2)
Where Fld = value_1

The second query is effectively what I get when I use the
link master/link child properties. So, I want to use a
parameter in the query and set it in code.
Thanks,
Paul
 
Paul said:
I have a subform, and the RecordSource of the subform is
a query that contains a parameter. I am prompted to
enter the value of the parameter every time I navigate to
a different record in the parent form. However, I want
to set the parameter's value in code, avoiding manual
entry.

I need to set the parameter value, and requery the
subform, every time the parent form navigates to a new
record. Can this be done in code? The value of the
parameter is a field that is available in the parent form.
[snip]


Instead of using a pop-up prompt parameter, use a form
control reference. For example, instead of having a
criteria of [employee], use Forms!yourform.txtEmployee

No code required.
 
Back
Top