Question : Show All Records In Query if Nothing Selected in Listbox

Hi Experts,
I have a series of list boxes that populate temp tables that I have been using for a query.  I want to make it so that if nothing is selected in the list box the query would not be filtered (show all), if something is in the list box it would use the information stored in the temp table (the contents of the multi-select list box).  I tried multiple variations of the criteria below in the query with no luck:

Like IIf(IsNull([Forms]![Menu]![ListDivision]),"*",In (Select Division FROM TempDivision))

Any help is greatly appreciated.

Answer : Show All Records In Query if Nothing Selected in Listbox

» but the code is over my head.

This doesn't seem to be the case, unless you are not the author of the snippet above. Anyway, I gather that you don't want to change anything in VB, and want to solve this using only query techniques. For this to work, you must only make sure that all temp tables are cleared (emptied) before any selection can be made.

WHERE (Not Exists (Select 1 FROM TempDivision) Or [Common System Name] In (Select Division FROM TempDivision))

I added brackets in case you want to do the same for several fields and temp tables. Please understand that this cannot be optimised easily by Jet. It would be better to produce directly:

WHERE [Common System Name] In ('red', 'green', 'blue')

... or nothing if no selection was made.

Random Solutions  
programming4us programming4us