• Button to Clear Grid when using a form (Access 97

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Button to Clear Grid when using a form (Access 97

    Author
    Topic
    #428785

    I am trying to use the following code on a button to clear the Advanced/Filter/Sort Grid on a form.
    I receive the following error. The command or action “ViewGrid” isn’t available now.
    What is the solution to this problem?
    Thank you in advance.

    Private Sub cmdRemoveFilter_Click()
    On Error GoTo Err_cmdRemoveFilter_Click

    DoCmd.RunCommand acCmdViewGrid
    DoCmd.RunCommand acCmdClearGrid
    DoCmd.RunCommand acCmdApplyFilterSort

    Exit_cmdRemoveFilter_Click:
    Exit Sub

    Err_cmdRemoveFilter_Click:
    MsgBox Err.Description
    Resume Exit_cmdRemoveFilter_Click

    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #996939

      acCmdViewGrid is for queries, it’s not valid for forms. Instead, use acCmdAdvancedFilterSort to activate the advanced filter/sort window:

      RunCommand acCmdAdvancedFilterSort
      RunCommand acCmdClearGrid
      RunCommand acCmdClose
      RunCommand acCmdApplyFilterSort

      • #996959

        Thank you Hans.

        It did not work at first. Then I commented out the 3rd line, RunCommand acCmdClose, and it worked fine.

        • #996962

          When I tried the code without the acCmdClose line, the advanced filter/sort window remained open in the background. Adding the line took care of that, but it’s not essential, so if it doesn’t work for you, leave it out by all means.

          • #996965

            Yeah, you are right, the grid does remain open.

            However, when I close the form the grid also goes away.

            Not as clean as the way yours works.

    Viewing 0 reply threads
    Reply To: Button to Clear Grid when using a form (Access 97

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: