My Assistant
![]()
Custom Search
|
![]() ![]() |
![]() |
![]() Post#1 | |
Posts: 17 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. |
![]() Post#2 | |
Posts: 17 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. |
![]() Post#3 | |
![]() Posts: 1,243 Joined: 26-December 12 From: Western Ma.,L.I.,N.Y.,Jupiter,Fl. ![]() | 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 |
![]()
Custom Search
|
![]() | Search Top Lo-Fi | 26th April 2018 - 02:23 PM |