On occasion it is necessary to use multi-select list boxes in queries. This topic presents one process to accomplish this.

The key to the process is the ValueInList(ListBoxKey, Value [, NoneSelected=True]) function.

ListBoxKey is any key contained in a ListBoxes collection (more later). (Trying to use Form!YourForm!YourListBox proves to be too complex for Access. We thus need to simply the expression, if not the process.)

Value is any value to test as being selected in the ListBox. (This would typically be the field whose value you want tested.)

(Optional) NoneSelected =

True (default) causes True to be returned if no items are selected in the list. (This is a preference of many programmer: If nothing is selected, then select all.)

False cause the function to return True only if the item is selected and it's itemdata = Value.

Prior to using the ValueInList function, you need to add the listbox to the ListBoxes Collection

ListBoxes.Add ListBox, ListBoxKey

Use ListBoxKey in the ValueInList function to refer to the ListBox. You can have multiple ListBoxes in the ListBoxes Collection, enabling you to use the function multiple times, even in the same query. It is recommended that you use

ListBoxes.Add ListBox, ListBoxKey to add all your listboxes in the Form's On Load event.

ListBoxes.Remove ListBoxKey to remove all your listboxes in the Form's UnLoad event.

To use the ValueInList function, add it to your criteria (SQL is easiest to describe):