Multi field filter on a form

Sue22

Registered User.
Local time
Today, 22:31
Joined
Mar 11, 2015
Messages
37
Hi there I have a filter on a form :
There is a text box (txtSearchP) where the user will enter their search term then click button to apply the filter:

Private Sub cmdSearchP_Click()
' Filter by Programme Description
Me.Filter = [Programme_Desc] Like "*" & Me.txtSearchP & "*"
Me.FilterOn = True
Me.Requery
End Sub

This works fine but actually I want to search two fields for the text entered in txtSearchP [Programme_Desc] OR [Programme]

I've tried this but it doesn't work:

Private Sub cmdSearchP_Click()
' Filter by Programme Code and Description
Me.Filter = [Programme_Desc] Like "*" & Me.txtSearchP & "*" OR [Programme] Like "*" & Me.txtSearchP & "*"
Me.FilterOn = True
Me.Requery
End Sub

Can anyone help I have been banging my head against the wall for ages with this now I've 'googled' and can't find anything helpful that I can understand odd examples I found didn't work. I know I could give the users two text boxes and two Buttons one for each and this would work but I don't want the form to be cluttered and it needs to be idiot proof.

Thanks in advance :confused: :banghead: :banghead: :banghead: :confused:
 
can you check what you have actually written in your post is what you are actually using in your code - the reason for asking is you say this

Me.Filter = [Programme_Desc] Like "*" & Me.txtSearchP & "*"
works - and I can't see how it can since it appears to be missing quotation marks.

If you are not providing the right information, it is likely you will be given the wrong advice.
 
OOPs got in such a tangle with this and posted the wrong line! It is

Me.Filter = "[Programme_Desc] Like " & Chr(34) & "*" & Me.txtSearchP & "*" & Chr(34)
 
OK, so try this

Code:
 Me.Filter = "[Programme_Desc] Like '*" & Me.txtSearchP & "' OR [Programme] Like '*" & Me.txtSearchP & "*'"
 

Users who are viewing this thread

Back
Top Bottom