On Apply Filter Oddity

Tee2

Registered User.
Local time
Today, 14:14
Joined
May 28, 2015
Messages
23
I have a form where I originally was going to have a table view subform but the users requested that it be a popup window so it could show more information and could be dragged to another monitor and viewed at the same time as a data entry form. I had the two forms up and running with the orderby and filters linked but if the user clicks the 'Toggle Filter' button it gets a bit confused. I was assuming the 'Toggle Filter' button was directly tied to FilterOn = true/false property but that doesn't seem to be the case.

Just to test what was going on I did this simple code:
Code:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)   
        If Me.FilterOn = False Then
            MsgBox "filter off"
        End If
        If Me.FilterOn = True Then
            MsgBox "filter on"
        End If
End Sub
it gets its wires crossed somehow. Am I missing something or is this strange behavior?
 
it gets its wires crossed somehow. Am I missing something or is this strange behavior?
You need to describe the exact symptoms of the problem. Obviously there aren't wires that get crossed. What is the outcome of your code?
 
The outcome of the code is when you toggle the filter (using the toggle filter button) off you get a message saying "filter ON" and when you toggle it on you get a message saying "filter off". So either I'm misunderstanding something or the toggle filter button is a bit weird. It returns the correct message when you apply/remove filters any other way.
 
Oh, OK, I see now. The ApplyFilter event occurs before the filter is applied. Note the Cancel parameter, which, if you set it to true, stops the filter from being applied.

Your message box always reports, accurately, the status of the FilterOn property before you set the filter.

To test another way, start a timer, and msgbox the status of FilterOn when the timer fires, like . . .
Code:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)   
    msgbox IIF(Me.FilterOn, "On", "Off")
    me.timerinterval = 200
End Sub

private sub form_timer
    me.timerinterval = 0
    msgbox IIF(Me.FilterOn, "On", "Off")
end sub
 
[FONT=&quot]Thanks! That makes some sense to me but your knowledge is somewhat wasted on me because I'm pretty clueless! I've been learning as I go so I don't know much about parameters in cases where the code builder automatically generates them.

I'm still not figuring out how to consistently link the filter/orderby on my two forms so that when they are both open and a filter changes on one it is applied to the other. What would

Code:
If CurrentProject.AllForms("Form2").IsLoaded Then
    If Me.FilterOn = False Then
        Forms("Form2").FilterOn = False
    ElseIf Me.FilterOn = True Then    
        Forms("Form2").Filter = Me.Filter
        Forms("Form2").FilterOn = True
    End If    
End If
I'm sure this code has problems but hopefully you can tell what my intention is here. What is the correct way to achieve that?
[/FONT]
 
You don't need to run any tests (except for that the other form is open). Just copy the settings to the other form.
Code:
If CurrentProject.AllForms("OtherForm").IsLoaded Then
    Forms("OtherForm").Filter = Me.Filter
    Forms("OtherForm").FilterOn = Me.FilterOn
End If
 
Thanks for your responses and patience with me. That makes sense, I had that originally but was trying to add more and more when it wasn't working with the ApplyFilter event and obviously that didn't solve anything. Should that code you provided work with the ApplyFilter event because I'm not able to get it to but that is likely due to my lack of understanding of the parameters.
 
Should that code you provided work with the ApplyFilter event
Well, apparently not, right? That seems to be the problem you are having, that during ApplyFilter, the filter has not yet been applied.

A little dodge you can do is in my other post with the timer. Handle ApplyFilter, but start a timer. Then, when the timer fires, do your operation. That way you let ApplyFilter finish, and then run your process after that. If Access was written today it would raise an ApplyFilterComplete event, but try something like . . .
Code:
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)   
    If CurrentProject.AllForms("OtherForm").IsLoaded Then Me.TimerInterval = 200
End Sub

private sub form_timer
    Me.TimerInterval = 0
    Forms("OtherForm").Filter = Me.Filter
    Forms("OtherForm").FilterOn = Me.FilterOn
end sub
See what's going on there?
 
Yep, that works perfectly. Thanks once again!
 

Users who are viewing this thread

Back
Top Bottom