Multiselect filtering in the form, using ListBox

Single Form

To achieve the desire in the title it is required a table, a form and a little VBA code. The form will contain, in addition to the table fields, a List Box control and a button.

List Box source: SELECT DISTINCT t_test.oras FROM t_test; 

For achieving the multi-selection, being in the Design View mode, we go to the Properties panel of the ListBox control, in the Other tab, where we select the Multi Select option to Simple (there is also the Extended option, the difference being the following: while for the Simple option it is enough to click successively to make the selection, for the Extended option it is necessary to press the Control key for non-contiguous selection or Shift for successive ones).

Filter Button Code

Form with Subform

As can be seen in the picture at the beginning, the disadvantage of placing a listbox in the same form it looks somewhat unsightly, having unused space. Solving the problem might be if we include another form. Also in that new form (parent) we bring the listbox. The code undergoes a small change, on the last lines, those under the comment “Filtering itself“. In the next picture you can see the result.


Author: Ovidiu.S

I am quite passionate about this professional area as if I know something - no matter how little - I want to share it with others.

Leave a Reply

Your email address will not be published.