Filter multiple fields with one search criteria on form

  • Thread starter Thread starter hlock
  • Start date Start date
H

hlock

I have a form with 2 fields - Name1 and Name2. I want to be able to enter
search criteria in my unbound text box and have it check both fields and
return records if the text is in either Name1 OR Name2. Currently, I have it
working for just one field.

If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername & "*"")
AND "
End If

How do I get it to search on Name2 as well? Thanks in advance.
 
If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername & "*"" Or
[Name2] Like ""*" & Me.txtfiltername & "*"") AND "
End If
 
The quotes don't look quite right.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Kipp Woodard said:
If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername & "*"" Or
[Name2] Like ""*" & Me.txtfiltername & "*"") AND "
End If


hlock said:
I have a form with 2 fields - Name1 and Name2. I want to be able to
enter
search criteria in my unbound text box and have it check both fields and
return records if the text is in either Name1 OR Name2. Currently, I
have it
working for just one field.

If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername &
"*"")
AND "
End If

How do I get it to search on Name2 as well? Thanks in advance.
 
Works perfect. Thank you for all of your help!!

Douglas J. Steele said:
The quotes don't look quite right.


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Kipp Woodard said:
If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername & "*"" Or
[Name2] Like ""*" & Me.txtfiltername & "*"") AND "
End If


hlock said:
I have a form with 2 fields - Name1 and Name2. I want to be able to
enter
search criteria in my unbound text box and have it check both fields and
return records if the text is in either Name1 OR Name2. Currently, I
have it
working for just one field.

If Not IsNull(Me.txtfiltername) Then
strWhere = strWhere & "([Name1] Like ""*" & Me.txtfiltername &
"*"")
AND "
End If

How do I get it to search on Name2 as well? Thanks in advance.
 
Back
Top