Reload Previous Filter

B

bhammer

AC2002
I can't seem to save the existing me.Filter to the me.Tag property during
either the OnFilter or OnApplyFilter events. I want to copy the previous
filter back into the me.Filter when the user clicks the cmdPreviousFilter
button.

The approach is this:
Every time the user applies a filter, save the old one in the tag property
so that if the user wants to go back to the previous filter, she can click
the Back button. I suppose I could make a new table to store the filter, but
that seems overkill. How can I read the filter before the new filter is
applied? I need a BeforeFilter event!

Brad
 
D

Dirk Goldgar

bhammer said:
AC2002
I can't seem to save the existing me.Filter to the me.Tag property during
either the OnFilter or OnApplyFilter events. I want to copy the previous
filter back into the me.Filter when the user clicks the cmdPreviousFilter
button.

The approach is this:
Every time the user applies a filter, save the old one in the tag property
so that if the user wants to go back to the previous filter, she can click
the Back button. I suppose I could make a new table to store the filter,
but
that seems overkill. How can I read the filter before the new filter is
applied? I need a BeforeFilter event!


I've occasionally wanted a BeforeFilter event, or at least an argument to
the ApplyFilter event procedure telling me what was in the form's Filter
property before.

It seems to me you might need to use the form's Tag property to hold both
the current and previous Filter values, separated by a delimiter. Then in
the ApplyFilter event you could parse them out, drop the old filter, make
the current filter the old filter, and make the new filter the current
filter. Something like:

'------ start of code ------
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)

Dim astrFilters() As String

If ApplyType = acApplyFilter Then
astrFilters = Split(Me.Tag, "|")
If UBound(astrFilters) <= 0 Then
Me.Tag = Me.Tag & "|" & Me.Filter
Else
astrFilters(0) = astrFilters(1)
astrFilters(1) = Me.Filter
Me.Tag = Join(astrFilters, "|")
End If
End If

End Sub


Private Sub cmdPreviousFilter_Click()

Dim astrFilters() As String
Dim intCancel As Integer

If Len(Me.Tag) = 0 Then Exit Sub

astrFilters = Split(Me.Tag, "|")

Me.Filter = astrFilters(0)
Me.FilterOn = True
Call Form_ApplyFilter(intCancel, acApplyFilter)

End Sub
'------ end of code ------

That's untested air code, but maybe something like that would work.
 
B

bhammer

Dirk,

Interesting strategy. I'll see if I can get it work. Seems like a fairly
common need, a Back button, but I'm unable to find any topics on this issue.

Brad
 
D

Dirk Goldgar

bhammer said:
Dirk,

Interesting strategy. I'll see if I can get it work. Seems like a fairly
common need, a Back button, but I'm unable to find any topics on this
issue.

Another approach would be to have a module-level array of filter strings,
and work it like a LIFO stack.
 

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