Hi All,
I'm currently building a database to collect information on a bunch of books. I'm trying to add a search function so that people can find specific books. However, I'm having trouble with the "AND" function.
Essentially, I want people to be able to search for example "twain" and "huckleberry" and still be able to find Mark Twain's Huckleberry Finn. Currently, if they typed in Twain Huckleberry - they would not be able to find anything.
Any ideas?
Thank you!!
Private Sub Search_Cmd_Click()
Dim strLinkCriteria As String
Dim lngLen As Long
'Search
If Not IsNull(Me.SearchAllCBO) Then
strLinkCriteria = strLinkCriteria & "(([Title] Like ""*" & Me.SearchAllCBO & "*"") OR "
strLinkCriteria = strLinkCriteria & "([Author] Like ""*" & Me.SearchAllCBO & "*"") OR "
strLinkCriteria = strLinkCriteria & "([Publication Year] Like ""*" & Me.SearchAllCBO & "*"")) AND "
End If
lngLen = Len(strLinkCriteria) - 5
If lngLen <= 0 Then
Me.FilterOn = False
Else
strLinkCriteria = Left$(strLinkCriteria, lngLen)
Me.Filter = strLinkCriteria
Me.FilterOn = True
End If
End Sub
I'm currently building a database to collect information on a bunch of books. I'm trying to add a search function so that people can find specific books. However, I'm having trouble with the "AND" function.
Essentially, I want people to be able to search for example "twain" and "huckleberry" and still be able to find Mark Twain's Huckleberry Finn. Currently, if they typed in Twain Huckleberry - they would not be able to find anything.

Any ideas?
Thank you!!
Private Sub Search_Cmd_Click()
Dim strLinkCriteria As String
Dim lngLen As Long
'Search
If Not IsNull(Me.SearchAllCBO) Then
strLinkCriteria = strLinkCriteria & "(([Title] Like ""*" & Me.SearchAllCBO & "*"") OR "
strLinkCriteria = strLinkCriteria & "([Author] Like ""*" & Me.SearchAllCBO & "*"") OR "
strLinkCriteria = strLinkCriteria & "([Publication Year] Like ""*" & Me.SearchAllCBO & "*"")) AND "
End If
lngLen = Len(strLinkCriteria) - 5
If lngLen <= 0 Then
Me.FilterOn = False
Else
strLinkCriteria = Left$(strLinkCriteria, lngLen)
Me.Filter = strLinkCriteria
Me.FilterOn = True
End If
End Sub