If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Search form using multiple tables and Union
I downloaded and redsigned a search form, which works great if I am looking
at one table. Now I am redesigning another one which uses multiple tables and a Union. After each key stroke in a textbox it should update my list box. However, I can't seem to get this thing to work. I have even tried it without the union to see what could happen, again it doesn't work. Can someone point out what I am doing wrong here? I would really appreciate it, thanks. txtSearchString2 = Me![txtLastName].Text strSQL = "SELECT * tblPracticalData.UniquePracticalIdentifier AS [Unique ID], tblTypeOfPractical.PracticalName AS [Type of Practical], tblTypeOfQualification.TypeOfQualification AS [Type of Qual], tblStudents.LName AS [Last Name], tblStudents.FName AS [First Name], tblStudents.STUDENTID" strSQL = strSQL & "FROM tblTypeOfPractical INNER JOIN (tblTypeOfQualification INNER JOIN (tblStudents INNER JOIN tblPracticalData ON tblStudents.StuID = tblPracticalData.StudentOne) ON tblTypeOfQualification.QUALTYPEID = tblPracticalData.Qual) ON tblTypeOfPractical.PRACTYPEID = tblPracticalData.Practical" strSQL = strSQL & "WHERE ((tblStudents.LName) Like '" & txtSearchString2 & "*')" strSQL = strSQL & "ORDER BY tblStudents.LName, tblStudents.FName, tblStudents.StudentID" strSQL = strSQL & "UNION SELECT * tblPracticalData.UniquePracticalIdentifier AS [Unique ID], tblTypeOfPractical.PracticalName AS [Type of Practical], tblTypeOfQualification.TypeOfQualification AS [Type of Qual], tblStudents.LName AS [Last Name], tblStudents.FName AS [First Name], tblStudents.STUDENTID" strSQL = strSQL & "FROM tblTypeOfPractical INNER JOIN (tblTypeOfQualification INNER JOIN (tblStudents INNER JOIN tblPracticalData ON tblStudents.StuID = tblPracticalData.StudentTwo) ON tblTypeOfQualification.QUALTYPEID = tblPracticalData.Qual) ON tblTypeOfPractical.PRACTYPEID = tblPracticalData.Practical" strSQL = strSQL & "WHERE ((tblStudents.LName) Like '" & txtSearchString2 & "*')" strSQL = strSQL & "ORDER BY tblStudents.LName, tblStudents.FName, tblStudents.StudentID" Me!lstResults.RowSource = strSQL Me!lstResults.Requery Me!txtLastName.SetFocus |
#2
|
|||
|
|||
Ok to get this to work I had come up with this.
strSQL = "SELECT * FROM [qryEvaluationPeople]" strSQL = strSQL & "WHERE ((qryEvaluationPeople.LName) Like '" & txtSearchString2 & "*')" strSQL = strSQL & "UNION SELECT * FROM [qryEvaluationPeople2]" strSQL = strSQL & "WHERE ((qryEvaluationPeople2.LName) Like '" & txtSearchString2 & "*')" However, this method prevents me to set my where clasue to something like WHERE ((qryEvaluationPeople.Last Name) Like '" & txtSearchString2 & "*')". If I want to use Column headings such as Last Name for my list box. Any solutions? "Fysh" wrote: I downloaded and redsigned a search form, which works great if I am looking at one table. Now I am redesigning another one which uses multiple tables and a Union. After each key stroke in a textbox it should update my list box. However, I can't seem to get this thing to work. I have even tried it without the union to see what could happen, again it doesn't work. Can someone point out what I am doing wrong here? I would really appreciate it, thanks. txtSearchString2 = Me![txtLastName].Text strSQL = "SELECT * tblPracticalData.UniquePracticalIdentifier AS [Unique ID], tblTypeOfPractical.PracticalName AS [Type of Practical], tblTypeOfQualification.TypeOfQualification AS [Type of Qual], tblStudents.LName AS [Last Name], tblStudents.FName AS [First Name], tblStudents.STUDENTID" strSQL = strSQL & "FROM tblTypeOfPractical INNER JOIN (tblTypeOfQualification INNER JOIN (tblStudents INNER JOIN tblPracticalData ON tblStudents.StuID = tblPracticalData.StudentOne) ON tblTypeOfQualification.QUALTYPEID = tblPracticalData.Qual) ON tblTypeOfPractical.PRACTYPEID = tblPracticalData.Practical" strSQL = strSQL & "WHERE ((tblStudents.LName) Like '" & txtSearchString2 & "*')" strSQL = strSQL & "ORDER BY tblStudents.LName, tblStudents.FName, tblStudents.StudentID" strSQL = strSQL & "UNION SELECT * tblPracticalData.UniquePracticalIdentifier AS [Unique ID], tblTypeOfPractical.PracticalName AS [Type of Practical], tblTypeOfQualification.TypeOfQualification AS [Type of Qual], tblStudents.LName AS [Last Name], tblStudents.FName AS [First Name], tblStudents.STUDENTID" strSQL = strSQL & "FROM tblTypeOfPractical INNER JOIN (tblTypeOfQualification INNER JOIN (tblStudents INNER JOIN tblPracticalData ON tblStudents.StuID = tblPracticalData.StudentTwo) ON tblTypeOfQualification.QUALTYPEID = tblPracticalData.Qual) ON tblTypeOfPractical.PRACTYPEID = tblPracticalData.Practical" strSQL = strSQL & "WHERE ((tblStudents.LName) Like '" & txtSearchString2 & "*')" strSQL = strSQL & "ORDER BY tblStudents.LName, tblStudents.FName, tblStudents.StudentID" Me!lstResults.RowSource = strSQL Me!lstResults.Requery Me!txtLastName.SetFocus |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Criterion - How to Write Query for Multiple Tables | jcinn | Running & Setting Up Queries | 1 | February 8th, 2005 12:42 PM |
Bring together tables without Union Query | bdehning | Running & Setting Up Queries | 1 | November 22nd, 2004 05:39 AM |
Form input in query, Union and crosstab query gives error msg | Christian | Running & Setting Up Queries | 2 | November 17th, 2004 05:00 PM |
Query to search multiple identical tables | Jim VanGordon | Running & Setting Up Queries | 9 | August 13th, 2004 01:34 AM |
"UNION" Query with different fields in the two tables | Dkline | Running & Setting Up Queries | 5 | July 30th, 2004 09:05 PM |