Self-made version of filter by selection - help (1 Viewer)

phual

Registered User.
Local time
Yesterday, 17:26
Joined
Jun 20, 2009
Messages
27
I'm helping out with a database at work and we have a need for a complex filter function. Due to our 'low-to-no tech' user base, the perfect solution (the built in 'filter by form' function) is neither obvious nor intuitive enough.

The approach we want to take is something like this (very simplified version - there are significantly more fields in the real version, which led us to rule out a number of possible approaches to a solution).


The left side of the screen shows a selection of fields from the main table and the right hand side mirrors these fields for selecting search/filter criteria.

Our first attempt had these search fields named in the format "FilterField1" set with no control source. The idea was that the user would set the criteria as they wanted them and then hit the search button. The button would run a macro that would be a series of ApplyFilter commands:

ApplyFilter where condition: [Field1]=[forms]![frmFilterTest]![FilterField1]
ApplyFilter where condition: [Field2]=[forms]![frmFilterTest]![FilterField2]
ApplyFilter where condition: [Field3]=[forms]![frmFilterTest]![FilterField3]
ApplyFilter where condition: [Field4]=[forms]![frmFilterTest]![FilterField4]

This sort of worked in that the user could select the values they wanted and hit search to return the correct results. However, if they then changed their search parameters and hit search again, Access recalled the original values and not the new ones. It made no difference whether the exiting filter was removed (by selecting 'remove filter' from the tool bar) - the only way to reset the parameters stored in MS Access' memory was to close and reopen the form.

We made a variety of increasingly complex attempts (such as putting the search criteria in a subform, storing the criteria in their own table, etc.), but suffice it to say we made no progress. I'm sure that the answer is going to be reasonably simple, and probably subtle, but I'll be damned if I can figure it out or find an answer through Google.

Any suggestions?

One further criteria - we want to avoid modules if possible. Macros are reasonably easy to explain to someone who may need to make changes in the future, but real code is beyond the 'I can learn this' psychological barrier for most non-techies'

Edit: corrected some of the more glaring typos - shouldn't have written this when I was so tired....
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Today, 10:26
Joined
Jan 20, 2009
Messages
12,856
Requery the form fields when they are updated. I think this refreshes the value in memory.
Think this has to be in a VBA procedure but not too painful.

On Update event:
[forms]![frmFilterTest]![FilterField1].Requery
etc
 

phual

Registered User.
Local time
Yesterday, 17:26
Joined
Jun 20, 2009
Messages
27
I knew that it would be something stupidly simple!

The action does appear in macros, so the revised macro would be:

Requery
ApplyFilter where condition: [Field1]=[forms]![frmFilterTest]![FilterField1]
ApplyFilter where condition: [Field2]=[forms]![frmFilterTest]![FilterField2]
ApplyFilter where condition: [Field3]=[forms]![frmFilterTest]![FilterField3]
ApplyFilter where condition: [Field4]=[forms]![frmFilterTest]![FilterField4]

Simple as that!

Thanks

Stuart
 

phual

Registered User.
Local time
Yesterday, 17:26
Joined
Jun 20, 2009
Messages
27
Okay, that problem was fixed easily, but it's allowed me to discover what I suspect to be a much more difficult problem.

When you apply a filter by form, it effectively writes a query with condition A AND condition B AND etc.

When I run the ApplyFilter action from a macro, it seem to reset the results from any existing filter. For example:

Requery
ApplyFilter where condition: [Field1]=[forms]![frmFilterTest]![FilterField1]
ApplyFilter where condition: [Field2]=[forms]![frmFilterTest]![FilterField2]
ApplyFilter where condition: [Field3]=[forms]![frmFilterTest]![FilterField3]
ApplyFilter where condition: [Field4]=[forms]![frmFilterTest]![FilterField4]

is the same as

Requery
ApplyFilter where condition: [Field4]=[forms]![frmFilterTest]![FilterField4]

because each ApplyFilter runs on all records and not the subset of records presented by the previous ApplyFilter.

I can't see any solution to this without going into VB, and even then my skills are such I only think that I could do with with nesting (which becomes more impractical as the number of fields increase).

Thoughts?
 

Users who are viewing this thread

Top Bottom