Access VBA Filtering form and charts by a combo box list

Viewed 21

I have a form that has charts and textboxes and a list, the form has no control source. and I have one combobox that has date list, based on that list I want to filter the data on the form and reload the charts and text boxes to view the filtered data by the selected date.

I reached up to this point but unfortunately it's not filtering

my code on the after update event

Private Sub cmbFindCustomer_AfterUpdate()

  'declare variables
  Dim sFilter As String

  'in this case, the ID is text so the ID value
  'needs to be wrapped in single quotes.
  sFilter = "[Date]= '" & Me.cmbFindCustomer & "'"

  'assign the filter value,and turn filtering on

  
 Me.Filter = sFilter
  Me.FilterOn = True
  Me.Recalc
  Forms!Main.Requery
  Forms!Main.Repaint
  
  
End Sub

1 Answers

A date field is not text but Date, and a combobox always returns text, so you need to convert the selected value and format it as a date value expression:

sFilter = "[Date] = #" & Format(Me!cmbFindCustomer.Value, "yyyy\/mm\/dd") & "#"
Related