Apply Filter

  • Thread starter Thread starter gr
  • Start date Start date
G

gr

Hello!

hi, i'm trying to apply a filter on a form depending on a
criteria comming from a cbo box.

My syntax looks like this but is not working at all
(doesn't filter, finds no match even when there is)

strFilter = "[Forms]![frmMD]![sfrmMeasurementDevices].
[Form]![SubCatID].Column(1) Like " & Me!cboCategory
If (Me!cboCategory <> "(All)") Then
Me.sfrmMeasurementDevices.Form.Filter = Eval
(strFilter)
Me.sfrmMeasurementDevices.Form.FilterOn = True
Else
....... more code ...

I tried using only
strFilter = "SubCatID.Column(1) Like " & Me!cboCategory
But then I got an "Undefined function error"
Using
strFilter = "SubCatID.Column(1) Like " & Me!cboCategory
Me.sfrmMeasurementDevices.Form.Filter = Eval(strFilter)
Returns a "Can not find Name SubCatID"

Any help will be appreciated.
I got a previous answer about coordinating comboboxes, I'm
not trying to do that just to filter my form. Let me know
if you need more details.

gr
 
Your filter looks like a string, so the code would be something like
(aircode):

If Me.cboCategory <> "<All>" Then
Me.Filter = "[SubCatID] = '" & Me.cboCategory & "'"
Me.FilterOn = True
Else
Me.FilterOn = False
End If

Note the quotes.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Hello thank you for your response.
But cboCategory is an unbound that holds in Column(0) an
autonumber CatID and in Column(1) the Category name
(string) so I think I don't need the quotations.
cboSubCatID is also an unbound combo of 3 columns. Column
(0) is SubCatID -number- , Column(1) is CatID, Column(2)
is Subcategory Name.
There's a bound field named SubCatID which is a lookup
field of 3 columns. Column(0) SubCatID, Column(1) CatID,
Column(2) Subcategory name.
Unbound cbobox cboSubCat filters the form using the
following statement:
strFilter = "SubCatID Like " & Me!cboSubCat
If (Me!cboSubCat <> "(All)") Then
Me.sfrmMeasurementDevices.Form.Filter = strFilter
Me.sfrmMeasurementDevices.Form.FilterOn = True
Else
Me.sfrmMeasurementDevices.Form.FilterOn = False
End If

This works perfect. but if the user only selects a
Category (not a subcat.) I want to filter by CatID which
is the second column of the lookup field so I think I need
a statement similar to:
strFilter = "Forms!frmMD!sfrmMeasurementDevices!
SubCatID.Column(1) Like " & Me!cboCategory

Which is not working..

Any help will be appreciated.
-----Originalnachricht-----
Your filter looks like a string, so the code would be something like
(aircode):

If Me.cboCategory <> "<All>" Then
Me.Filter = "[SubCatID] = '" & Me.cboCategory & "'"
Me.FilterOn = True
Else
Me.FilterOn = False
End If

Note the quotes.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Hello!

hi, i'm trying to apply a filter on a form depending on a
criteria comming from a cbo box.

My syntax looks like this but is not working at all
(doesn't filter, finds no match even when there is)

strFilter = "[Forms]![frmMD]![sfrmMeasurementDevices].
[Form]![SubCatID].Column(1) Like " & Me!cboCategory
If (Me!cboCategory <> "(All)") Then
Me.sfrmMeasurementDevices.Form.Filter = Eval
(strFilter)
Me.sfrmMeasurementDevices.Form.FilterOn = True
Else
...... more code ...

I tried using only
strFilter = "SubCatID.Column(1) Like " & Me!cboCategory
But then I got an "Undefined function error"
Using
strFilter = "SubCatID.Column(1) Like " & Me!cboCategory
Me.sfrmMeasurementDevices.Form.Filter = Eval(strFilter)
Returns a "Can not find Name SubCatID"

Any help will be appreciated.
I got a previous answer about coordinating comboboxes, I'm
not trying to do that just to filter my form. Let me know
if you need more details.

gr


.
 
Back
Top