Clear Filter on closing a form

G

Guest

Hello,

Waht is the VBA for every closing the form, the filter will atuotomatically
removed, because often that it will remember the filter and the clerck said "
I can not see my data that I just entered" they he/she did not remove the
filter.

On the form property I would write the VBA on close event.

Thanks in advance,

Frank
 
D

Douglas J. Steele

Try:

Private Sub Form_Close()

Me.FilterOn = False
Me.Filter = vbNullString

End Sub
 
G

Guest

Doug,
I have put your code, but it does not work. I tried to open my form than I
put cursor in the amount field, and typed >1000000, then I filter by form, it
worked, it showed only amount bigger than 1 million, than I closed the form,
and I open it again, and I see the one that I typed in the amount field
1000000 still showed.

I appreciate your idea again.

Thanks

Frank
 
D

Douglas J. Steele

You sure the code is actually firing? Put a breakpoint in there to make sure
it is.
 
Joined
Aug 4, 2012
Messages
2
Reaction score
0
I have the same problem. I tried the code suggested and it didn't work either.
I have tried all sorts of code including:
Private Sub cmdRemoveFilters_Click()
If Me.Form.FilterOn Then
Me.Form.Filter = ""
Me.Form.FilterOn = False
End If
End Sub

I can't get the filter to clear. If I click on the button with the above code, which will permit me to filter by form again without anything in the field which I had put the previous selection criteria, but when I close the form, open it again, the same field in which I had the original search criteria still contains the search criteria. The only thing that works it to first click on the button with the above code, then filter by form.
But why won't it clear the filter on close (or open or load or whatever)?
 
Joined
Aug 4, 2012
Messages
2
Reaction score
0
I just fournd this. It seems to work. I say that will a little intrepedation but I tried ti several times and it seemed to clear the filter. It is not my code, and I don't take responsibilty for it.
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Err

Me.Filter = ""
Me.FilterOn = False

Form_Open_Exit:
Exit Sub

Form_Open_Err:
MsgBox Err.Number & " - " & Err.Description
Resume Form_Open_Exit

End Sub
 

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