Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Button to Clear Grid when using a form (Access 97

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button to Clear Grid when using a form (Access 97

    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

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button to Clear Grid when using a form (Access

    Thank you Hans.

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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Button to Clear Grid when using a form (Access

    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.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Button to Clear Grid when using a form (Access

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •