Hi, I am a newbie using Access 2003. I am trying to apply a filter to a form and then re-filtering that forms records again. Basically I have my main form and when I wish to filter I click a button and a pop-up box comes up with several lists. I select what I want from the lists and click the button on the pop-up to perform the filter. It filters my main form, however if I want to filter again to narrow my search then I do the same thing and it reset my main form and does the filter again. So If I do a filter for "apples" and then do one for "red" I want the second filter to pull all the "red, apples" not everything that is red. Here is the code I am working with.
Code:
Private Sub Search_Click()
Dim strOr As String
Dim strDoc As String
Dim varSelect As Variant
Dim ctl As Control
strDoc = "frmDescription"
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list1")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list2")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list3")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list4")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list5")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list6")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
Set ctl = Forms!frmPhotoKeywordSearch.Controls("list7")
For Each varSelect In ctl.ItemsSelected
strOr = strOr & "[Photo Keywords] Like '*" & ctl.ItemData(varSelect) & "*' OR "
Next varSelect
' lose the last ' OR '
strOr = Left(strOr, Len(strOr) - 4)
DoCmd.OpenForm strDoc, acNormal, , strOr
DoCmd.Close acForm, "frmPhotoKeywordSearch"
End Sub
Comment