Filter multiple fields with one search criteria on form

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.
 
K

Kipp Woodard

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

Douglas J. Steele

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.
 
H

hlock

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top