Using Filter on Data Tab in Access Form

Posted on 2013-09-20
Medium Priority
Last Modified: 2013-09-21
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
Question by:marku24
LVL 50

Accepted Solution

Dale Fye earned 1000 total points
ID: 39510800
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 = ""
          '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.

Author Closing Comment

ID: 39512451
this worked great - thanks

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question