Solved

When/how to clear a filter

Posted on 2011-03-09
7
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

Expert Comment

by:Dale Fye
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

632 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