I have a query that fills a list box with records that contain words selected in a simple multiselect list box.
It works okay, however I am struggling to find how I can avoid duplication of records where more than 1 word is contained. I have tried re arranging the code to try and use the Distinct word, but have spent so long with so many permutations not getting it right. Help!! Thanks
It works okay, however I am struggling to find how I can avoid duplication of records where more than 1 word is contained. I have tried re arranging the code to try and use the Distinct word, but have spent so long with so many permutations not getting it right. Help!! Thanks
Code:
Dim strList1 As String, item As Variant
strList1 = ""
For Each item In Me.KeySearch.ItemsSelected
strList1 = strList1 & ",'" & Replace(Me.KeySearch.ItemData(item), "'", "''") & "'"
Next item
MySql = "SELECT Keywords.KeywordID, Keywords.Keyword, KEYWORD.KeywordID, MAIN.IDNumber, MAIN.ID1"
MySql = MySql & " FROM (Keywords INNER JOIN KEYWORD ON Keywords.KeywordID = KEYWORD.KeywordID)"
MySql = MySql & " INNER JOIN (MAIN INNER JOIN JUNCTION1 ON MAIN.ID1 = JUNCTION1.ID1) ON KEYWORD.ID2 = JUNCTION1.ID2"
MySql = MySql & " WHERE Keywords.Keyword IN (" & Mid(strList1, 2) & ")"
Me.MM.RowSource = MySql