remove filter

Posted on 2005-05-03
Last Modified: 2008-02-26
i used the "command button wizard" to build the following - it applies a filter based on the selection.  this button is on my form "ReadFrm"

i need to be able to remove the filter as well.  I  would like to be able to apply the filter with the first click and then remove the filter with the second click???????? or at least add a second button to remove the filter. (nothing in the "command button wizard" on removing the filter????

Private Sub Command97_Click()
On Error GoTo Err_Command97_Click

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, , acMenuVer70

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Command97_Click
End Sub
Question by:ssblue
    LVL 17

    Expert Comment

    This should clear your filter:

    Me.Filter = ""
    Me.FilterOn = True


    Author Comment

    so do i create a new button and use your code to remove the filter?
    LVL 17

    Accepted Solution

    Do do this with one button you would have to set up a Public variable in a module:
    Public FilterApplied as Integer

    In the On Open event of your form, clear the variable:
    FilterApplied = false

    Now in the On Click of your button:

    If FilterApplied then
        Me.Filter = ""
        Me.FilterOn = True
        FilterApplied = False
        DoCmd.ApplyFilter , "FilterField= FilterValue"   '<----If FilterValue is text then you would use "FilterField = 'FilterValue'"
        FilterApplied = True
    end if


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 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

    11 Experts available now in Live!

    Get 1:1 Help Now