Applying more than 1 filter

  • Thread starter Thread starter lecoughlin
  • Start date Start date
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.
 
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"
 
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.
 
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.
 
Back
Top