Solved

When/how to clear a filter

Posted on 2011-03-09
7
308 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

863 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

27 Experts available now in Live!

Get 1:1 Help Now