Filter

G

Guest

Hello,

I made a form with 2 command buttons: a button to apply the filter and a
button to remover the filter

I would like to filter on client name

e.g. If I type Royal* or Royal? I would like to see all the records starting
with Royal

I'm still not familiar with visual basic and this is what I typed in my
event procedure but it doesn't work!

Private Sub cmdFilter_Click()
Me.Filter = "matter_name Like '*" & Me.txtFilterNaam.Value & "*'

Me.FilterOn = True
End Sub

Please go easy on me I would also would like to remove the filter by using
my second button.

Thank you very much
 
A

Allen Browne

Assuming that txtFilterNaam is an unbound control:

Private Sub cmdFilter_Click()
If Me.Dirty Then Me.Dirty = False 'Save first.
Me.Filter = "[matter_name] Like ""*" & Me.txtFilterNaam & "*"""
Me.FilterOn = True
End Sub

Private Sub cmdRemoveFilter_Click()
If Me.Dirty Then Me.Dirty = False 'Save first.
Me.FilterOn = False
Me.txtFilterNaam.Value = Null 'Clear the filter box.
End Sub

Note that there is no need to type the wildcards into the box, since they
are added in code.
 
G

Guest

Try:

Me.Filter ="matter_name Like'" & "*" & Me.txtFilterNaam.Value & "*" & "'

And in the filter remove button:

Me.Filter = ""
Me.FilterOn = False
 
G

Guest

thank you very much, you're an angel

Allen Browne said:
Assuming that txtFilterNaam is an unbound control:

Private Sub cmdFilter_Click()
If Me.Dirty Then Me.Dirty = False 'Save first.
Me.Filter = "[matter_name] Like ""*" & Me.txtFilterNaam & "*"""
Me.FilterOn = True
End Sub

Private Sub cmdRemoveFilter_Click()
If Me.Dirty Then Me.Dirty = False 'Save first.
Me.FilterOn = False
Me.txtFilterNaam.Value = Null 'Clear the filter box.
End Sub

Note that there is no need to type the wildcards into the box, since they
are added in code.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

halima said:
Hello,

I made a form with 2 command buttons: a button to apply the filter and a
button to remover the filter

I would like to filter on client name

e.g. If I type Royal* or Royal? I would like to see all the records
starting
with Royal

I'm still not familiar with visual basic and this is what I typed in my
event procedure but it doesn't work!

Private Sub cmdFilter_Click()
Me.Filter = "matter_name Like '*" & Me.txtFilterNaam.Value & "*'

Me.FilterOn = True
End Sub

Please go easy on me I would also would like to remove the filter by using
my second button.

Thank you very much
 
G

Guest

If you only need to look for fields that start with a value you don't want
the first '*' - using '*' & fieldname & '*' will give you anything containing
the value anywhere in it. Use fieldname & '*' if you only want to match
things that start with the value.
 

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