Solved

When/how to clear a filter

Posted on 2011-03-09
7
307 Views
Last Modified: 2012-08-13
I have two forms:
1. A search Input form (with a search button that starts my code)
2. A results form that consists of a master form that has some "function" buttons and a subform within which the results are displayed in a datasheet

When the user clicks Search, the code examines all of the possible parameters and creates the "where" clause for the ResultsSub form; however, I can't get it to forget the filter once the ResultsMain/Sub form closes. So if the user clicks the "back to search" or "main menu" button on the ResultsMain, it doesn't drop the filter.  I currently have a command in the ResultsSub form at the "on close" event to set the filter to nothing:
me.filter = ""
but it isn't working.

When / where should i put the me.filter = ""  command?

thanks
0
Comment
Question by:epuglise
7 Comments
 
LVL 75
ID: 35087733
Try clearing it prior to each new search ... in the Search button Code.

Me.YourSubFormControlName.Form.Filter = ""
Me.YourSubFormControlName.Form.FilterOn = False

' other search code ...

'  set new filter.

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 35087871
You mention: When the user clicks Search, the code examines all of the possible parameters and creates the "where" clause for the ResultsSub form

Does this actually modify the "WHERE" clause of the SQL string that is the Recordsource for the subform, or does it modify the Filter property of the subform?  If it modifies the WHERE clause, setting the "Filter" property to "" will not do anything for you.
0
 

Author Comment

by:epuglise
ID: 35087920
@DBMX: can I set that form filter property if that form is not open? Because that form won't be open when the call is made.

@ fyed: I pass the where clause via open args and the clause ends up in the Filter property of the form.

thanks all!
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:epuglise
ID: 35087929
so to clarify the forms:

I have a Search form

I have a Results form.

they're two different forms. the Results form consists of a Master and Sub form.
0
 
LVL 75
ID: 35087980
"can I set that form filter property if that form is not open? "
I'm afraid not.  Form needs to be open.

"I pass the where clause via open args and the clause ends up in the Filter property of the form."
You really just need to pass either a Filter string OR a WHERE clause ... like so:

DoCmd.OpenForm "YourFormName",acFormDS ,, <WHERE CLAUSE HERE>

The WHERE Clause will do the filtering ...

mx
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 35089857
I have Access 2007/2010 pain too.
In Access 2003 a filter does not survive opening and closing.
They do in 2007/2010, and I run a mixed environment

ClearFiltersonOpen clears any filters as a form opens
To be clear, it runs in the Form Open event.

KillFilters gets used before I put out a production version to kill any filter on any form.
It opens every form in design mode, sets the filter to "" , saves the form and closes it.

Curses on those who invented FilterOnLoad!
'in the forms module
Private Sub Form_Open(Cancel As Integer)
Call ClearFiltersonOpen(Me.Name)
End Sub


'-----------------------------------------------------------------

'in a regular module

Public Function ClearFiltersonOpen(FormName As String)
'Because Access 12+ allows a filter of survive opening and closing a form
'it becomes necessary to kill filters

Forms(FormName).Filter = ""
Forms(FormName).FilterOn = False


End Function


'-----------------------------------------------------------------


Private Sub KillFilters()
'On Error GoTo myerr
Dim f As AccessObject
Dim MyProject As Object
Dim myform As Form
Set MyProject = Application.CurrentProject
For Each f In MyProject.AllForms
    DoCmd.OpenForm f.Name, acDesign
    'MsgBox Nz(Forms(f.Name).Filter, "no filter")
    Forms(f.Name).Filter = ""
    Forms(f.Name).FilterOn = False
    DoCmd.Close acForm, f.Name, acSaveYes
Next f
        
Exit Sub

myerr:
'MsgBox Err.Number & " " & Err.Description
Resume Next

End Sub

Open in new window

0
 

Author Closing Comment

by:epuglise
ID: 35098266
Thanks!!!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now