B
BruceM
I'm trying to find the best way of applying or removing part of a filter.
In a Purchase Order database I have a command button with the following code
in the Click event to filter for just the Purchase Orders by the vendor on
the current record:
Dim strThisVendor As String
strThisVendor = "VendorID =" & Me.VendorID
Me.FilterOn = Not Me.FilterOn
If Me.FilterOn = True Then
DoCmd.ApplyFilter , strThisVendor
End If
This works fine for setting or removing the filter. Now I want the option
of filtering according to whether the PO is approved. The presence of a
name in the Approved field is the criteria. That command button code may be
something like:
Dim strApproved As String
strApproved = "Approved =""" & Me.Approved & """"
Me.FilterOn = Not Me.FilterOn
If Me.FilterOn = True Then
DoCmd.ApplyFilter , strApproved
End If
However, I want these two filters to work independently of each other. That
is, I would like the ability to filter for the current vendor, then to apply
or remove the second filter without affecting the first filter. As it
stands, if I have filtered for one vendor's POs, FilterOn = True, so the
second filter turns off the first filter, which means the second filter
won't be applied.
I wonder if I should have something like:
Public strThisVendor as String
and so forth for all of the filter strings in the Declarations section of
the form's code module, and to combine the strings in a Public sub that I
would call in the Click event of each command button. I suppose each string
could begin with AND:
strThisVendor = "AND VendorID =" & Me.VendorID
At the end of establishing the filter I could lop off the first four letters
in order to get a meaningful string. However, I really don't know if this
will work at all, or if it will work whether it is a reasonable approach, or
whether I am overlooking something simpler.
In a Purchase Order database I have a command button with the following code
in the Click event to filter for just the Purchase Orders by the vendor on
the current record:
Dim strThisVendor As String
strThisVendor = "VendorID =" & Me.VendorID
Me.FilterOn = Not Me.FilterOn
If Me.FilterOn = True Then
DoCmd.ApplyFilter , strThisVendor
End If
This works fine for setting or removing the filter. Now I want the option
of filtering according to whether the PO is approved. The presence of a
name in the Approved field is the criteria. That command button code may be
something like:
Dim strApproved As String
strApproved = "Approved =""" & Me.Approved & """"
Me.FilterOn = Not Me.FilterOn
If Me.FilterOn = True Then
DoCmd.ApplyFilter , strApproved
End If
However, I want these two filters to work independently of each other. That
is, I would like the ability to filter for the current vendor, then to apply
or remove the second filter without affecting the first filter. As it
stands, if I have filtered for one vendor's POs, FilterOn = True, so the
second filter turns off the first filter, which means the second filter
won't be applied.
I wonder if I should have something like:
Public strThisVendor as String
and so forth for all of the filter strings in the Declarations section of
the form's code module, and to combine the strings in a Public sub that I
would call in the Click event of each command button. I suppose each string
could begin with AND:
strThisVendor = "AND VendorID =" & Me.VendorID
At the end of establishing the filter I could lop off the first four letters
in order to get a meaningful string. However, I really don't know if this
will work at all, or if it will work whether it is a reasonable approach, or
whether I am overlooking something simpler.