Simple button for complex filter

Forum rules
No question in this section please
For any question related to a topic, create a new thread in the relevant section.
Post Reply
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Simple button for complex filter

Post by Villeroy »

Think of a (sub-)form with a categories listbox where you want to filter by many category-IDs or some other set of filter criteria form that takes minutes to set up.
1. Open the form for editing and turn off design mode.
2. Do the work once using the form based filter. In the filter navigator, the resulting filter may look like this one showing all records where some CID is Null or eiher one of 4, 10, 1, 9 or 7:
Bildschirmfoto von 2023-05-26 14-19-27.png
Bildschirmfoto von 2023-05-26 14-19-27.png (7.11 KiB) Viewed 3824 times
3. Turn off desgn mode. The form's data properties will show the current filter string like this:
Bildschirmfoto von 2023-05-26 14-20-35.png
Bildschirmfoto von 2023-05-26 14-20-35.png (16.96 KiB) Viewed 3824 times
Copy that filter string.

4.1. Add a push button to the filtered (sub-)form with property "Toggle" = Yes.
4.2. Paste the filter string into the button's "Additional information" property.
4.3. Assign the following macro to the button's execute event:

Code: Select all

Sub Button_Filter_OnOff(e)
	b = cBool(e.Selected)
	m = e.Source.Model
	s = m.Tag
	frm = m.Parent
	REM print frm.Filter
	frm.ApplyFilter = b
	frm.Filter = s
	frm.reload()
End Sub
5. Before saving the modified form, consider if you want the form to load filtered or not.
5.1. If yes, set the button's "Default state" to "Selected" and save the form with the set filter string.
5.2. If you want to load the form unfiltered by default, delete the filter string from the form properties and keep the button's "Default state" as "not selected".
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply