Solved

When/how to clear a filter

Posted on 2011-03-09
7
310 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

808 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