none
enable command button to ApplyFilter RRS feed

  • Question

  • I'm trying to put a pair of command buttons onto a form to enable users to:

    1. enter filter criteria, then

    2. after they enter the criteria, apply the filter

    1. is easy enough with "DoCmd.RunCommand acCmdFilterByForm"

    2. would work with "DoCmd.RunCommand acCmdApplyFilterSort", except that I can't figure out how to activate my command button "cmdApplyFilter". The code "Me.cmdApplyFilter.Enabled = True" throws a runtime error.

    I've looked at a lot of discussions, and it seems the only way to do this is by clicking on the ribbon or quick access toolbar. Does anyone know how to activate a command button on the form while in filter by form mode?


    Saturday, January 21, 2017 4:23 PM

Answers

  • Controls such as command buttons don't work at all in Filter by Form mode, only controls that correspond to data.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, January 21, 2017 4:38 PM

All replies

  • 1. enter filter criteria, then

    2. after they enter the criteria, apply the filter

    Hi Gordon,

    In the Click event of the command button you could set the OnFilter and OnApplyFilter properties of the form.

    Imb.

    Saturday, January 21, 2017 4:37 PM
  • Controls such as command buttons don't work at all in Filter by Form mode, only controls that correspond to data.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, January 21, 2017 4:38 PM
  • But once I start the mode that allows the criteria for the filter to be entered, all the command buttons are disabled. That's what I'm trying to get around.

    Sunday, January 22, 2017 1:56 PM
  • Hi GordonPrince,

    >>I'm trying to put a pair of command buttons onto a form to enable users

    To filter Form records, I would suggest you try suggestion from Imb, and you could try DoCmd.ApplyFilter.

    Here is a simple code:

    Private Sub Command27_Click()
    
    DoCmd.ApplyFilter , "[Title]='Issue4'"
    
    End Sub
    

    If it did not meet your requirement, it would be helpful if you could share us a screen shot about your current Form, and your current requirement.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 23, 2017 6:58 AM
  • What I'm trying to do is find a way to make a command button on the form active so it will apply the filter using the criteria the user has entered in the "Filter by Form" mode, without having to train users to find the "Apply Filter/Sort" button on the ribbon.

    I want to have a pair of command buttons on the form: 

    one to enter "Filter by Form" mode, 

    the other to "Apply Filter/Sort".

    I was thinking I'd make clicking on one hide or disable the other so only one is active at a time. But maybe there's not a way to do that and this requires training users to find the "Apply Filter/Sort" button from the ribbon.

    Monday, January 23, 2017 12:02 PM
  • I want to have a pair of command buttons on the form: 

    one to enter "Filter by Form" mode, 

    the other to "Apply Filter/Sort".

    I was thinking I'd make clicking on one hide or disable the other so only one is active at a time. But maybe there's not a way to do that and this requires training users to find the "Apply Filter/Sort" button from the ribbon.

    Hi Gordon,

    It is easy to make a couple of command buttons with a descriptive caption, where users only have to click on to do where it is meant for.

    In all my applications I do not use ribbons or taskbars at all. All functionality is available on the place where it is needed.

    Imb.

    Monday, January 23, 2017 12:55 PM
  • How do you enable the command button that applies the filter, so the user can click on it after they have provided the criteria in "filter by form" mode?
    Monday, January 23, 2017 12:59 PM
  • How do you enable the command button that applies the filter, so the user can click on it after they have provided the criteria in "filter by form" mode?

    Hi Gordon,

    The command buttons are there. In the Click event of the command button you can write the instructions to ask the user how to filter, and to set the OnFilter and OnFilterBY properties of the form.

    Personnally I present the users a list on a new form with the available fields (or controls), a field depending criterion for how to filter (equal, starting, >, Null, ...) and a value. After accepting a new Where clause is constructed. I do not use the OnFilter and OnFilterBy properties, but I use a new sql-string that is assigned to the form's RecordSource.

    Imb.

    Monday, January 23, 2017 1:22 PM
  • I've done that when needed. I am searching for a simple way to enable the out of the box functionality where it is adequate. It seems using the button on the Quick Access Toolbar or Ribbon is the only way to do this.
    Monday, January 23, 2017 1:52 PM
  • Hi GordonPrince,

    As you have found, the button in the “Filter by Form” mode is disabled. So, you would not be able to use button event.

    What is your Access version? As my test under Access 2013, after you set filter options in “Filter by Form”, you could Right Click the Filter by Form->Apply Filter/Sort to filter the Form. I think it is much more convenience.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 24, 2017 2:35 AM