Solved

When/how to clear a filter

Posted on 2011-03-09
7
314 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 (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
Industry Leaders: 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Menus 6 58
question about a text field with default value 5 31
Queries: Select, then Append, then Delete 8 41
Cant delete records in query 8 50
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

752 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