Form Filter - How to Reverse Filter

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 04:36
Joined
Jul 15, 2008
Messages
2,271
Here is my new Form Filter - it works:)

How can I make it so the same button, when clicked again, will reverse the filter process - ie show all records again.
If possible - to avoid extra buttons.

Private Sub CmdFilterLateFeesOnlyUnpaid_Click()
On Error GoTo Err_CmdFilterLateFeesOnlyUnpaid_Click


Me.Filter = "RemainingLoan >0"
Me.FilterOn = True

Exit_CmdFilterLateFeesOnlyUnpaid_Click:
Exit Sub

Err_CmdFilterLateFeesOnlyUnpaid_Click:
MsgBox Err.Description
Resume Exit_CmdFilterLateFeesOnlyUnpaid_Click

End Sub
 
You could change the line Me.FilterOn = True to:
Me.FilterOn = Not Me.FilterOn

This will toggle the FilterOn between true and false for each button click.

You might also want to investigate the Toggle Button.

hth
Chris
 
You could change the line Me.FilterOn = True to:
Me.FilterOn = Not Me.FilterOn

This will toggle the FilterOn between true and false for each button click.

You might also want to investigate the Toggle Button.

hth
Chris

Thanks, This works although it would be good to change the button name or a label as each click is done. Two buttons allows for a label to be edited to display what the records reflect.

I will have to study up on some parts of Access I have side stepped. Toggle buttons, option groups etc.
 
You can simply use one button and in design view you set it to say Set Filter in the caption. Then you can have this code:
Code:
If Me.YourButton.Caption = "Set Filter" Then
   Me.Filter = "xxxxxxxxxxxxxxx whatever xxxxxxxx"
   Me.FilterOn = True
   Me.YourButton.Caption = "Remove Filter"
Else
  Me.Filter = ""
  Me.FilterOn = False
  Me.YourButton.Caption = "Set Filter"
End If

Of course make sure to change the applicable parts. :)
 
Works great - thanks Bob and stopher.

I can now go around and reduce the number of buttons.

I still need some help on the filter by two fields issue in another thread;)
 

Users who are viewing this thread

Back
Top Bottom