Can recordsource parameters be set in code?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using Access 97. 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
 
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.

Just use that control as (part of) the Subform's Master Link Field,
and the field that it is searching as the Child Link Field. Or,
explicitly reference the form control in the parameter:

=[Forms]![yourformname]![controlname]
 
Back
Top