Access:Union query: Where a field meets a condition not working
Posted on 2007-11-15
I have a form called "Students". On this form is a textbox called "txtStudent". Also on this form is a listbox called "StudentList". I also have two tables ("Table1"and "Table2") both tables have the following fields ("StudentName", "SS#", "Grade","Status")
When someone types a name in the textbox ("txtStudent") and presses enter it runs the code below:
[Forms]![Students]![StudentList].RowSource = "SELECT [StudentName], [SS#], [Grade], [Status] FROM TABLE1 UNION SELECT [StudentName], [SS#], [Grade], [Status] FROM TABLE2 WHERE [StudentName] =[Forms]![Students]![txtStudent] ORDER BY [StudentName];"
This code is supposed to display in the list box only those records with a "StudentName" equal to what the user typed in the textbox ("xtStudent"). Nonetheless the code displays all records anyway. Will someone help me make the code work?