From: bhammer on
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
From: Dirk Goldgar on
"bhammer" <bhammer(a)discussions.microsoft.com> wrote in message
news:CA8E3A07-5EB3-4704-9D00-04C0D41E23A4(a)microsoft.com...
> 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.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

From: bhammer on
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
From: Dirk Goldgar on
"bhammer" <bhammer(a)discussions.microsoft.com> wrote in message
news:18D5BAD0-E40C-43B0-BE92-1B2D45A19F43(a)microsoft.com...
> 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.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)