Using Filter on Data Tab in Access Form

I have a form that currently runs from a table.  I would like to use a combo box on my form (cboTeamFilter) to filter the form when selected.  Can I type this on the filter line in the data tab?  Like me.filter = cboTeamFilter?  or do I do in VBA on the change event of the combo box?  I would also need to reset the filter for all records to come back.  Thanks
marku24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
I generally do this in the AfterUpdate event of the combo box.  Code would look something like:

Private Sub cboTeamFilter_AfterUpdate

    if Len(me.cboTeamFilter & "") = 0 Then
         me.Filter = ""
    Else
          'Assumes that the [team] field is string
         me.Filter = "[Team] = '" & me.cboTeamFilter & "'"
         'Assumes that the [team] field is number
         'me.filter = "[Team] = " & me.cboTeamFilter
    End IF
    me.filterOn = Len(me.Filter) > 0

End Sub

With this syntax, you can simply delete the value from the combo to remove the filter.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marku24Author Commented:
this worked great - thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.