Select Data Source Based On Outcome Of

  • Thread starter Thread starter Chai
  • Start date Start date
C

Chai

I have a form that does not have a record source assigned to it. In the form
I have a combo box, and, after selecting something in the combo box I want
the form to be connected to a table or query. Don't know if this is
possible.

Chai
 
Here one way but all sources must have same fields or be able to be displayed
by a set of generic field aliases.

Base the form on a union query that uses a control (combo with 2 columns)
for criteria to determine which portion of the union query will have any
records to output.
SELECT tbl1.SomeName AS T_Name, tbl1.Name_X AS U_Name, tbl1.Name_Y AS V_Name
FROM tbl1
WHERE [Forms]![MyForm]![cbo1] = 1
UNION ALL SELECT tbl2.OtherName AS T_Name, tbl2.Q_Name AS U_Name,
tbl2.N_Name AS V_Name
FROM tbl2
WHERE [Forms]![MyForm]![cbo1] = 2
UNION ALL SELECT tbl3.Other AS T_Name, tbl3.VR_Name AS U_Name, tbl3.CB_Name
AS V_Name
FROM tbl3
WHERE [Forms]![MyForm]![cbo1] = 3;

You will need an AfterUpdate event on combo to refresh the query.
 
Back
Top