need to re-set filter when user clicks RemoveFilter tool icon

T

Trillium97

Hi. I'm using Accesss 2003.

I have a form with a combo box in the form header. The user must select a
workorder before records are shown. The after update event on this combo
box sets a filter on the data to this workorder. We want to minimize coding,
so we want the user to do further filters by using the filter by form (rarely
will they use that button) or the filter by selection (they will use this
button often) icons that are on the standard tool bars. They all like this
and it works great. The problem I'm having is when they remove the filter.
The icon that looks like a little funnel (standard toolbar icon) is either
labeled "Apply Filter" or "Remove Filter" depending on which way it will go.
It toggles between the two. This is all normal.

here's my event code (pardon some of the mess I've been debugging it)

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
Select Case ApplyType
Case Is = acShowAllRecords '0
If Me.SelectWorkorder > "" Then
Me.Filter = "WONumber = '" & Me.SelectWorkorder & "'"
Else
Me.SelectWorkorder .SetFocus
MsgBox "Please select a workorder", vbOKCancel + vbInformation,
"Need selection"
End If
Cancel = True
Case Is = acApplyFilter '1
MsgBox "applying filter: " & Me.Filter
End Select
End Sub

What I want is that if the user clicks Apply Filter, let it do its filter.
If the user clicks Remove Filter, set the filter to the workorder instead of
really showing all the records.

What I'm gettting is that ApplyType is always set to 1, no matter what. This
event always fires on the click of that button, and it always tells me
ApplyFilter is 1. But the tool works properly, it either applies the filter
or shows all records, and I can't figure out how to capture the Remove Filter
before it shows all the records so I can reset the filter to the workorder
and quit confusing the users.

Any suggestions please?
 
S

SteveM

The OnApplyFilter event runs when a filter is both applied and removed. You
may be able to use that to reset your form or set a flag that is used for a
reset somewhere else.

Steve
 
T

Trillium97

Yes, that's the event I'm using. it does indeed fire when a filter is either
applied or removed. The help on this topic seems to imply that the ApplyType
will tell me whether the action is going to apply or remove, but every time
it runs, ApplyType is set to Apply. Am I reading Microsoft's help
information incorrectly?

What I need to know is whether the user is expecting the filter to be
applied or removed. And I thought ApplyType would tell me that.

Thanks in advance for any thoughts and ideas.
 
T

Trillium97

Thanks for your suggestions, however I've already been there. In the link
you provided it says:
ApplyType Returns the type of filter that was applied.

however when I test it out, ApplyType is always set to acApplyFilter. The
action actully taken toggles between filtering and showing all records.

I also tried to use the FilterOn property, and it appears to always be set
to true when this event runs. I'm stumped.
 
T

Trillium97

I thought of that. Me.Filter is always set to the filter that is _Currently_
in place. That is, even if it's about to remove the filter, me.filter is
whatever is currently showing. And if they are building a filter based on
filter by selection, the old filter is what's showing. For example, if they
are already filtered on workorder and they add a filter on a part, the
me.filter will show the workorder.

Thanks for your suggestions! It still seems to me that ApplyFilter should
tell me which way the filter is going, and I just can't figure out why it
isn't.

I'm tempted to add another button that allows them to clear the filter and
return to the workorder selected. That will be easier than figuring out the
problem with the Remove Filter tool.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top