Full Version: "toggle Filter" Button Not In Sync With 'filteron' Property
UtterAccess Forums > Microsoft® Access > Access Forms
pepewaw
First of all, sorry if this isn't the adequate category for the post, but couldn't find a more appropiate one; since this 'bug' happens within a form.
I'm having a problem withing a form: whenever I filter an existing form using the big filter button, I can then use "On Apply Filter" event of the form to check for this, and then read the 'FilterOn' property. This wokrs fine until I use the "toggle filter" button (either the one that's in the ribbon bar, or the one that's in the record navigator bar at the bottom)
So, here's what happens:
first of all, the VBA code (I've reduced the code as much as possible):
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
'this code only reads wether a filter is on or off, and display the status on a textbox
If Form_Table1.FilterOn = True Then
Form_Table1.filterOnBox = "Filter is on"
Else
Form_Table1.filterOnBox = "Filter is off"
End If
End Sub

The code should just update the textbox named "Form_Table1.filterOnBox" whenever a filter is applied / unapplied. And this works fine, except when you click the "toggle filter" button. When you click it the first time, nothing happens. Every time you click it afterwards, it changes (and given that the first change wasn't correctly updated, it starts displaying the oposite status). This gets fixed if you set up a new filter using the filter button.
Otested this in Access 2007 and Access 2010 and got the same behavior, and I'm wondering if it's a bug or the code.
Any help, tips, or owrkaround are highly appreciated, and also thanks for taking the time to read the post.
- Jose.
Daryl S
Jose -
First, Welcome to UtterAccess! welcome2UA.gif
The ApplyFilter method occurs before the filter is actually applied. Notice there is a Cancel parameter, so you can cancel the filter before it is applied if you want. That is why the code seems backwards - it is running your test before the filter is applied or removed.
Also, from the help:
Hope that helps!
- Daryl
pepewaw
Thanks Daryl, this certainly clears the doubt as to why it was happening! " style="vertical-align:middle" emoid=":thumbup:" border="0" alt="thumbup.gif" />
anted to ask you, if there's an "After filter has been applied and running" kind of event?
Meanwhile I'm gonna experiment with the timer event. Not the most elegant solution, but might get something working.
Thanks again,
- Jose
Daryl S
Jose -
You can try the Current event of the form:
CODE
Private Sub Form_Current()
If Me.FilterOn Then
    Me.filterOnBox = "Filter is On"
Else
    Me.filterOnBox = "Filter is Off"
End If
End Sub

- Daryl
pepewaw
And just when I got the timer thing working, this works even better.
Thanks again!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.