Clearing Filters (Filter by Form)

Joined
Jul 30, 2012
Messages
2
Reaction score
0
Using Microsoft Access 2010

I can't seem to get the filter cleared either when closing or opening a form. I have the following code for a button that will do it, but it won't work on open or close.
Private Sub cmdRemoveFilters_Click()
If Me.Form.FilterOn Then
Me.Form.Filter = ""
Me.Form.FilterOn = False
End If
End Sub

In another button which I have labeled Search, I have the following, but it won't work all the time.
Private Sub CmdSearch_Click()
If Me.Form.FilterOn Then
Me.Form.Filter = ""
Me.Form.FilterOn = False
DoCmd.RunCommand acCmdFilterByForm
Else:
DoCmd.RunCommand acCmdFilterByForm
End If
End Sub

I have tried to put the first part of the code in the close event and in the open and current event, but it won't work. What am I doing wrong? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top