Filter Not Clearing properly

ALui

Registered User.
Local time
Today, 02:54
Joined
May 11, 2009
Messages
19
Hi, I've been having trouble with my filter not clearing properly. Essentially what I have is a split-form which displays all the appointments for a certain location when I click a "View Schedule" button. This works, but I also have a "View All" button to take me back to show all my records and remove any filters.
This is my code for "View All"

Private Sub View_All_Click()
DoCmd.ShowAllRecords
Me.FilterOn = False
Me.Filter = ""
Me.OrderBy = ""
End Sub

The problem is if I click "View Schedule" again with different day(s) in my combo boxes, then the previous filter is applied, no matter what I do (even with the Clear All Filters under Advanced). The filter will only "disappear" when I close the form and re-open it fresh.
 
Hi ALui,

Try putting this code into your "View All":

DoCmd.ShowAllRecords

'Purpose: Clear all the search boxes in the Form Footer, and show all records again from the details form.
Dim ctl As Control
'Clear all the controls in the Form Footer section, replace (acFooter) with the section your input boxes are, e.g. acHeader.
For Each ctl In Me.Section(acFooter).Controls
Select Case ctl.ControlType

Case acTextBox, acComboBox
ctl.Value = Null
Case acCheckBox
ctl.Value = False

End Select
Next
'Turn the forms filter off
Me.FilterOn = False


David,
 
Hi David,
Thanks for your response. Your solution successfully resets all my control values, but unfortunately, it wasn't able to clear the filter.
I'm still trying to apply multiple filters (NOT at the same time), but without going through the hassle of closing and opening the form.
 
Last edited:
Add this code into the "View All" and "View Schedule" buttons:

If me.Dirty then
me.Dirty = False
End if

Place this code into the "View All" button
Me.Filter = "(False)"
Me.FilterOn = True
 
Do I add the code to the top or bottom of my segments? I've tried both and neither have seemed to have worked. I've come up with a temporary solution where at the end of my View All code, I have...

Me.FilterOn = False
Me.Filter = ""
DoCmd.Close
DoCmd.OpenForm "Day Schedule"


Also, isn't the Dirty property applicable to just records?
 
I've found a totally alternate solution that you can whip up in less than ten minutes, using queries rather than filters (which seem to be much better!).
What I've done is gone to the form's recordsource and used a query with different criteria. My View Schedule button now has the event Requery, which will display what you were looking for via combo boxes, hope this helps anyone who was reading along.
 

Users who are viewing this thread

Back
Top Bottom