Hi there,
Long-time user of these forums (previously fluffyozzy). I am stuck with something and hoping someone can point me in the right direction. I have a listbox with a number of fields and a search box on a form. I have done this before and always worked but this time it is not working and I am thinking maybe it is something to do with the underlying query behind the search. Listbox displays the records fine.
Query 1: This shows projects and people associated with it, with multiple rows for each project and the personID
SELECT tblLinkProjects.PersonRoleLinkID, tblLinkProjects.ProjectID, tblProjects.ProjectGroup, tblLinkProjects.PersonID, tblLinkProjects.PersonRoleID, tblLinkProjects.DegreeID, tblLinkProjects.PersonActive, tblProjects.ProjectTitle, tblProjects.NHSRef, tblProjects.IRASRef, tblProjects.CurrentStatus, tblProjects.CurrentStatusDate, DLookUp("ProjectStatus","tblProjectStatus","ProjectStatusID = " & [CurrentStatus]) AS Status, tblProjects.ProjectEndDate, qryPeople.PersonName
FROM tblProjects INNER JOIN (tblLinkProjects INNER JOIN qryPeople ON tblLinkProjects.PersonID = qryPeople.PersonID) ON tblProjects.ProjectID = tblLinkProjects.ProjectID;
Query 2: This uses the previous query and gets the records on a single row per project and concatenates people associated with the project
SELECT p.ProjectID, Max(p.ProjectGroup) AS MaxOfProjectGroup, Max(p.PersonID) AS PersonID, Max(p.PersonRoleID) AS PersonRoleID, Max(p.ProjectTitle) AS MaxOfProjectTitle, Max(p.NHSRef) AS MaxOfNHSRef, Max(p.IRASRef) AS MaxOfIRASRef, Max(p.Status) AS MaxOfStatus, Max(p.CurrentStatusDate) AS MaxOfCurrentStatusDate, Max(p.PersonName) AS PersonName, SimpleCSV("SELECT PersonName FROM qryProjectsMainPrep WHERE ProjectID = " & [p].[ProjectID] & " AND [PersonRoleID] = 2") AS Students, SimpleCSV("SELECT PersonName FROM qryProjectsMainPrep WHERE ProjectID = " & p.ProjectID & " AND [PersonRoleID] = 3") AS Staff, Max(p.ProjectEndDate) AS MaxOfProjectEndDate
FROM qryProjectsMainPrep AS p
GROUP BY p.ProjectID
HAVING (((Max(p.PersonActive))=Yes));
Listbox: This is based on the Query 2
Search textbox: This is based on a copy of Query 2 to "reduce as you type" sort of search within the listbox. The code behind it:
Private Sub ProjectsSearchBox_Change()
Dim strSQL As String
Dim searchText As String
searchText = Replace(Me.ProjectsSearchBox.Text, "'", "''") ' Escape single quotes
' Build the dynamic SQL query with wildcard search for each field
strSQL = "SELECT * FROM qryProjectsMainSearch " & _
"WHERE ProjectTitle LIKE '*" & searchText & "*' OR " & _
"NHSRef LIKE '*" & searchText & "*' OR " & _
"IRASRef LIKE '*" & searchText & "*' OR " & _
"CurrentStatusDate LIKE '*" & searchText & "*' OR " & _
"Students LIKE '*" & searchText & "*' OR " & _
"Staff LIKE '*" & searchText & "*' OR " & _
"ProjectEndDate LIKE '*" & searchText & "*' " & _
"GROUP BY ProjectID " & _
"HAVING Max(PersonActive) = Yes " & _
"ORDER BY ProjectEndDate"
' Set the listbox RowSource
Me.ProjectsListBox.RowSource = strSQL
It is not working and I can't figure out why, no error message produced. The listbox just goes blank and stays that way. Can anyone give me some advice please?
Long-time user of these forums (previously fluffyozzy). I am stuck with something and hoping someone can point me in the right direction. I have a listbox with a number of fields and a search box on a form. I have done this before and always worked but this time it is not working and I am thinking maybe it is something to do with the underlying query behind the search. Listbox displays the records fine.
Query 1: This shows projects and people associated with it, with multiple rows for each project and the personID
SELECT tblLinkProjects.PersonRoleLinkID, tblLinkProjects.ProjectID, tblProjects.ProjectGroup, tblLinkProjects.PersonID, tblLinkProjects.PersonRoleID, tblLinkProjects.DegreeID, tblLinkProjects.PersonActive, tblProjects.ProjectTitle, tblProjects.NHSRef, tblProjects.IRASRef, tblProjects.CurrentStatus, tblProjects.CurrentStatusDate, DLookUp("ProjectStatus","tblProjectStatus","ProjectStatusID = " & [CurrentStatus]) AS Status, tblProjects.ProjectEndDate, qryPeople.PersonName
FROM tblProjects INNER JOIN (tblLinkProjects INNER JOIN qryPeople ON tblLinkProjects.PersonID = qryPeople.PersonID) ON tblProjects.ProjectID = tblLinkProjects.ProjectID;
Query 2: This uses the previous query and gets the records on a single row per project and concatenates people associated with the project
SELECT p.ProjectID, Max(p.ProjectGroup) AS MaxOfProjectGroup, Max(p.PersonID) AS PersonID, Max(p.PersonRoleID) AS PersonRoleID, Max(p.ProjectTitle) AS MaxOfProjectTitle, Max(p.NHSRef) AS MaxOfNHSRef, Max(p.IRASRef) AS MaxOfIRASRef, Max(p.Status) AS MaxOfStatus, Max(p.CurrentStatusDate) AS MaxOfCurrentStatusDate, Max(p.PersonName) AS PersonName, SimpleCSV("SELECT PersonName FROM qryProjectsMainPrep WHERE ProjectID = " & [p].[ProjectID] & " AND [PersonRoleID] = 2") AS Students, SimpleCSV("SELECT PersonName FROM qryProjectsMainPrep WHERE ProjectID = " & p.ProjectID & " AND [PersonRoleID] = 3") AS Staff, Max(p.ProjectEndDate) AS MaxOfProjectEndDate
FROM qryProjectsMainPrep AS p
GROUP BY p.ProjectID
HAVING (((Max(p.PersonActive))=Yes));
Listbox: This is based on the Query 2
Search textbox: This is based on a copy of Query 2 to "reduce as you type" sort of search within the listbox. The code behind it:
Private Sub ProjectsSearchBox_Change()
Dim strSQL As String
Dim searchText As String
searchText = Replace(Me.ProjectsSearchBox.Text, "'", "''") ' Escape single quotes
' Build the dynamic SQL query with wildcard search for each field
strSQL = "SELECT * FROM qryProjectsMainSearch " & _
"WHERE ProjectTitle LIKE '*" & searchText & "*' OR " & _
"NHSRef LIKE '*" & searchText & "*' OR " & _
"IRASRef LIKE '*" & searchText & "*' OR " & _
"CurrentStatusDate LIKE '*" & searchText & "*' OR " & _
"Students LIKE '*" & searchText & "*' OR " & _
"Staff LIKE '*" & searchText & "*' OR " & _
"ProjectEndDate LIKE '*" & searchText & "*' " & _
"GROUP BY ProjectID " & _
"HAVING Max(PersonActive) = Yes " & _
"ORDER BY ProjectEndDate"
' Set the listbox RowSource
Me.ProjectsListBox.RowSource = strSQL
It is not working and I can't figure out why, no error message produced. The listbox just goes blank and stays that way. Can anyone give me some advice please?