click event of list box

  • Thread starter Thread starter george
  • Start date Start date
G

george

Hi,
I have two forms based on two tables t1 and t2 (each form
based on one table). I also have a union query based on
the two tables. Based on this query I have a list box. Is
it possible to program the click event of the list box so
that it opens the corresponding form (out of the two
forms) for the specific entry? Could you give me some
sample code?

UNION QUERY:

SELECT ti.field1, t1.field2
FROM t1
UNION
SELECT t2.field1, t2.field2
FROM t2

Thanks in advance, George
 
The first thing that I would advise is to change the UNION
query to include a column indicating which table the row
came from e.g.

SELECT ti.field1, t1.field2, 1
FROM t1
UNION
SELECT t2.field1, t2.field2, 2
FROM t2

You will then have to increase the ColumnCount to 3

Then the Click event can be coded along the folowing line

Dim strForm As String

If list0.column(2) = 1 then
strForm = "Form1"
Else
strForm = "Form2"
End if

Docmd.OpenForm strForm,,,"field1 = '" & listo & "'"

In the above example, list0 is the name of the list box. I
have assumed that field1 and field2 are identically named
text columns in both tables.

Hope This Helps
Gerald Stanley MCSD
 
Back
Top