Query with parameter ?

  • Thread starter Thread starter TonyB
  • Start date Start date
T

TonyB

Hi,
I have a question regarding running a query which returns different fields
based upon a value passed to the query ?

To explain, I have a subform based upon a query which returns several fields
from a table. The table has two fields, a UK price and
a US price. This subform is displayed inside the main form and what I would
like to do is the subform to display one price or the
other depending on the setting of a checkbox in the main form by passing the
True/False value of the checkbox to the subform
and its query. Is this possible ? Is there a better way of doing this ?
TIA
Tony
 
You would base the subform on a query. The query could be something
like;

SELECT Table1.ItemID, IIf([Forms]![Form1]![chkUSD],[USPrice],[UKPrice])
AS LocalPrice
FROM Table1;

The query would check the value of the form checkbox (in this case I
have called the checkbox chkUSD) with a boolean where if the box is
checked you display the USPrice otherwise you show the UKPrice. The
query would fail if the form was not open. If you wanted to use this
query elsewhere you might consider using a hidden field on a hidden
form that's opened at startup and populated appropriately then for the
duration of the session. This could be manipulated if required during
a session.

Let me know how you get on...

Regards

Barry-Jon
 
Back
Top