Access VBA - data in form using condition

Posted on 2012-08-22
Last Modified: 2012-08-22

I have an Access form that is bound to a table called "Tasks".
What VBA code would I use to filter the data so only records
where column "Project" equals "P1" are shown
Question by:murbro
    LVL 61

    Accepted Solution

    Me.filter = "project ='p1'"
    Me.filterOn = True

    Expert Comment


    You can insert a button, e.g. called btn_filter and add the code below to the buttons 'On Click' event:

    Private Sub btn_filter_Click()

    Me.Filter = "Project = 'P1'"
    Me.FilterOn = True

    End Sub

    Note that the criteria has ' ' around it, since it is a string. If it is a numerical value no ' ' needs to be around it. If it is a date criteria you put # # around it.



    Author Closing Comment


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now