Filter a subform from a dropdown menu

  • Thread starter Thread starter Christian Davidsson
  • Start date Start date
C

Christian Davidsson

Hi there everyone!

Need some help on filtering a subform according to some criterias on the
mainform. Let me try and describe the scenario.

mainForm has got two dropdown menus (named: "chain" and "item" and two
grouped radio fields (result saved as "filterBy"). The subForm needs to be
filterd according to "chain" if filterBy = 1 and according to "item" if
filterBy = 2.

The code I've written looks like this (but doesn't work):
----------
Private Sub filterBy_AfterUpdate()
If filtreraBy = 1 Then GoTo Filter_chain
GoTo Filter_item

Filter_chain:
With Me.[subForm].Form
.Filter = "Chain = ""chain_dropdown"""
.FilterOn = True
End With

Filter_artikel:
With Me.[subForm].Form
.Filter = "Item = ""item_dropdown"""
.FilterOn = True
End With

End Sub
----------

I've tried a couple of variations mentioned here earlier, but haven't been
able to make the filter work correctly.

Thanks in advance,
Christian Davidsson
 
The Filter_artikel: should obviously be Filter_item:

Changed that, but it still doesn't work..

// Christian Davidsson
 
Hello again,

Done some changes to the code:

----------
Private Sub Item_dropdown_AfterUpdate()
If filterBy = 1 Then GoTo Filter_chain
GoTo Filter_item

Filter_chain:
With Me.[subForm].Form
.Filter = "[Chain] = """ & Me.Chain_dropdown & """"
.FilterOn = True
End With
GoTo EndItem

Filter_item:
With Me.[subForm].Form
.Filter = "[Item] = """ & Me.Item_dropdown & """"
.FilterOn = True
End With
GoTo EndItem

EndItem:
End Sub
----------
The filter now works on the items, but not on the chains. When set to chain,
it sends me a pop-up asking for the value. Could it be because the chain
values contain a ( and ) character? Currently, the chain value is
"<chainname> (<number of stores>)".

// Christian Davidsson


Christian Davidsson said:
The Filter_artikel: should obviously be Filter_item:

Changed that, but it still doesn't work..

// Christian Davidsson


Christian Davidsson said:
Hi there everyone!

Need some help on filtering a subform according to some criterias on the
mainform. Let me try and describe the scenario.

mainForm has got two dropdown menus (named: "chain" and "item" and two
grouped radio fields (result saved as "filterBy"). The subForm needs to be
filterd according to "chain" if filterBy = 1 and according to "item" if
filterBy = 2.

The code I've written looks like this (but doesn't work):
----------
Private Sub filterBy_AfterUpdate()
If filtreraBy = 1 Then GoTo Filter_chain
GoTo Filter_item

Filter_chain:
With Me.[subForm].Form
.Filter = "Chain = ""chain_dropdown"""
.FilterOn = True
End With

Filter_artikel:
With Me.[subForm].Form
.Filter = "Item = ""item_dropdown"""
.FilterOn = True
End With

End Sub
----------

I've tried a couple of variations mentioned here earlier, but haven't been
able to make the filter work correctly.

Thanks in advance,
Christian Davidsson
 
Rather than apply a filter, just set the Master/Child links in your subform
control to the multiple fields you want to link.
--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
Back
Top