Code Examples

Select a Saved Filter

acCmdAdvancedFilterSort, acCmdLoadFromQuery, acCmdWindowHide, acCmdApplyFilterSort

This example allows the user to select a filter to apply to a form without needing to see the Filter Design window. To try out this example add a command button to your form. Call it cmdFilter and paste the code in the form module.

'***************** Code Start *******************
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.

Private Sub cmdFilter_Click ()
  On Error GoTo errFilter 
  'Turn off screen refresh
  Application.Echo False
  'Open the filter design window
  DoCmd.RunCommand acCmdAdvancedFilterSort
  'Display the Applicable Query dialog
  DoCmd.RunCommand acCmdLoadFromQuery
  'Hide the filter design window
  DoCmd.RunCommand acCmdWindowHide
  'Apply the selected filter
  DoCmd.RunCommand acCmdApplyFilterSort
ExitFilter:
  'Turn the screen refresh back on
  Application.Echo True
  Exit Sub
errFilter:
  Select Case Err
    Case 2501
      'Cancel selected in the Applicable Query Window 
      ' close the filter window
      DoCmd.Close
    Case Else
      MsgBox Err.Number & ":- " & vbCrLf & Err.Description
  End Select
  Resume ExitFilter
End Sub

'****************** Code End ********************

© 1998 - 2011 Terry Wickenden TKW Design Site developed maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.