Applying more than 1 filter

L

lecoughlin

Good afternoon,
I have a button on a form, that when clicked I would like to apply 2
filters to the records being shown. I thought that this code would
work:

Private Sub filteroption_DblClick(Cancel As Integer)
DoCmd.ApplyFilter , "pilot_id like '*_0'"
DoCmd.ApplyFilter , "GrantYear = 2003"
End Sub

But it seems to only apply whichever filter is listed second.

How would I apply both?

Thanks in advance.
 
R

Rick Brandt

Good afternoon,
I have a button on a form, that when clicked I would like to apply 2
filters to the records being shown. I thought that this code would
work:

Private Sub filteroption_DblClick(Cancel As Integer)
DoCmd.ApplyFilter , "pilot_id like '*_0'"
DoCmd.ApplyFilter , "GrantYear = 2003"
End Sub

But it seems to only apply whichever filter is listed second.

How would I apply both?

Thanks in advance.

One filter per form...

DoCmd.ApplyFilter , "pilot_id like '*_0' AND GrantYear = 2003"
 
R

Rick Brandt

When I do this, I get the error: "type mismatch"

Well those are just your two filters combined together so I see no reason
for that error.

A filter is nothing more than a query's WHERE clause without the word
"where" at the front.
Build a query that gives you the result you want and then switch to SQL view
and look at the WHERE clause.

That phrase with the double-quotes changed to single-quotes and the whole
thing surrounded by double-quotes should be what your filter looks like.
 
B

Bob Quintal

Well those are just your two filters combined together so I
see no reason for that error.

A filter is nothing more than a query's WHERE clause without
the word "where" at the front.
Build a query that gives you the result you want and then
switch to SQL view and look at the WHERE clause.

That phrase with the double-quotes changed to single-quotes
and the whole thing surrounded by double-quotes should be what
your filter looks like.

the other thing that the OP may have missed is the comma.
DoCmd.ApplyFilter takes two optional parameters, the Where
Clause comes second, so must be preceded by a comma.
 

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