splats
Technical User
- Jan 2, 2003
- 131
Greetings
I have a search that is just not working the way it should. Textbox with an option group and a command button on a form. It works great for "All" and "the exact phrase" options but includes records that do not meet the criteria for "Any" option. Basically when I enter in a couple of words in the textbox and select an option, I would like the search to be based on the option that is selected.
Below is the code. Any ideas would be appreciated.
Thank you
TinaT
I have a search that is just not working the way it should. Textbox with an option group and a command button on a form. It works great for "All" and "the exact phrase" options but includes records that do not meet the criteria for "Any" option. Basically when I enter in a couple of words in the textbox and select an option, I would like the search to be based on the option that is selected.
Below is the code. Any ideas would be appreciated.
Thank you
TinaT
Code:
Private Sub cmdSearch_Click()
Dim arrSearch() As String
Dim i As Integer
Dim strWhere As String
'Dim rst As DAO.Recordset
Dim lngRcnt As Long
If txtSearchFor <> "" Then
If fraUsing = 1 Then ' any
arrSearch() = Split(txtSearchFor, " ", -1, 1)
For i = 0 To UBound(arrSearch)
If i = 0 Then
strWhere = strWhere & " ("
Else
strWhere = strWhere & " OR "
End If
strWhere = strWhere & " ([Abbreviation] & ' ' & [File #] & ' ' & [Title] & ' ' & [Hyper Link] & ' ' & [Consultant] & ' ' & [Month] & ' ' & [Year]& ' ' & [Study TypeID] LIKE '*" & Trim(arrSearch(i)) & "*')"
Next
ElseIf fraUsing = 2 Then ' all
arrSearch = Split(txtSearchFor, " ", -1, 1)
For i = 0 To UBound(arrSearch)
If i = 0 Then
strWhere = strWhere & " ("
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " ([Abbreviation] & ' ' & [File #] & ' ' & [Title] & ' ' & [Hyper Link] & ' ' & [Consultant] & ' ' & [Month] & ' ' & [Year]& ' ' & [Study TypeID] LIKE '*" & Trim(arrSearch(i)) & "*')"
Next
Else
strWhere = strWhere & " ("
strWhere = strWhere & " ([Abbreviation] & ' ' & [File #] & ' ' & [Title] & ' ' & [Hyper Link] & ' ' & [Consultant] & ' ' & [Month] & ' ' & [Year]& ' ' & [Study TypeID] LIKE '*" & Trim(txtSearchFor) & "*')"
End If
strWhere = strWhere & ") "
[Frm-Subrec2].Form.Filter = strWhere
[Frm-Subrec2].Form.FilterOn = True
Else
[Frm-Subrec2].Form.FilterOn = False
End If
End Sub