Filter Datasheet based on Combo Box selection

  • Thread starter Pasadena-D via AccessMonster.com
  • Start date
P

Pasadena-D via AccessMonster.com

I have a SubForm that displays in Datasheet view. I want to add a Combo Box
just above the SubForm that the user can select the Pay_Period_Ending_Date,
and once selected I would like the Datasheet to filter based on this date.
Can someone please direct me as to how I can do this?
 
D

Daryl S

Pasadena-D -

You can put your combobox in the header section of the subform. Then based
on the selection in the combobox, you can apply your filter like this (using
your fieldnames and combobox name). If the user will click on an item, you
can put this in the Click event of the combobox:

DoCmd.ApplyFilter , "[DateFieldName] = #" & Me.ComboboxName.Column(0) & "#"
 
P

Pasadena-D via AccessMonster.com

Daryl....This is what I did based on your feedback:
- ComboBox64 - OnClick - [Event Procedure]
- Microsoft Visual Basics Code:
Private Sub Combo64_Click()
DoCmd.ApplyFilter , "[Pay_Period_Ending] = #" & Me.Combo64.Column(1)
& "#"
End Sub

If Combo64 is unbound, then I get a "Run-Time Error '2491": The action or
method is invalid because the form or report isn't bound to a table or query".
If I bound it to the same query as the SubForm, then it will not let me type
a date nor select one from the list. Sorry for not fully understanding this
whole thing.
 
D

Daryl S

Pasadena-D -

That is because the combo box is in the parent form instead of the subform.
You can put the combo box in the header of the subform instead of outside the
subform.

Otherwise you will need to set the Filter property of the subform like this
(instead of the DoCmd):

Me.subformName.Form.Filter = "[Pay_Period_Ending] = #" &
Me.Combo64.Column(1) > & "#"
 

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