UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Clear Filters On Form.unload, Access 2010    
 
   
MrAutomation
post Mar 19 2017, 05:10 PM
Post#1



Posts: 2
Joined: 19-March 17



I'm sure this is a duplicate thread, but I've searched and searched and tried many many things and I just don't know why it isn't working!
All that I want to do is clear my filters using VBA when I close the forms if the Me.FilterOn property is false. ie:

CODE
Private Sub Form_Unload(Cancel As Integer)
    If Me.FilterOn = False Then
        Me.Filter = ""
    End If
End Sub


I have a form with a datasheet subform. The code should apply to the subform, as that is where the filters lie. I've tried running the code on the subform, as above, and on the main form like this:

CODE
Private Sub Form_Unload(Cancel As Integer)
    If Me.mySubForm.Form.FilterOn = False Then
        Me.mySubForm.Form.Filter = ""
    End If
End Sub


I've also tried making my own close button in case the form unload was causing issues:

CODE
Private Sub ctrl_CloseButton_Click()
    If Me.mySubForm.Form.FilterOn = False Then
        Me.mySubForm.Form.Filter = ""
    End If
    DoCmd.Close acForm, Me.Name
End Sub


I've also tried making a function on the subform to clear the filter which is called when I run the main form close button and including a save:

CODE
Private Sub ctrl_CloseButton_Click()
    If Me.mySubForm.Form.FilterOn = False Then
        Me.mySubForm.Form.fnClearFilter
    End If
    DoCmd.Close acForm, Me.Name
End Sub

-----On Subform:--------
Function fnClearFilter
     Me.Filter =""
     DoCmd.Save
End Function


Based on what I've read. Any of these should work, but every time I open the form (with FilterOn as false when I closed it), the filters come back up again. What am I missing? Also, I do want the FilterOnLoad property as true. I want to retain filters for the users. The only issue that when they unfilter, it should remain that way when they open the form again.
This post has been edited by MrAutomation: Mar 19 2017, 05:20 PM
Go to the top of the page
 
MrAutomation
post Mar 19 2017, 05:43 PM
Post#2



Posts: 2
Joined: 19-March 17



OK I've done a workaround.
I already have a "Variables" table, so on Form_Unload I'm saving the Me.FilterOn value to the table, and on Form_Load I clear the filters if the value of the variable on the table is False.

Easy peasy. If anyone wants I can put up a more detailed explanation.
Go to the top of the page
 
moke123
post Mar 19 2017, 06:17 PM
Post#3



Posts: 987
Joined: 26-December 12
From: Western Ma., USA


are you saving edits to the form while the filter is on?
I think i've run into situations where this saved the filter to the form
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    27th May 2017 - 11:48 PM