I have 5 multiple select listboxes in Excel. The selected content of every listbox is each written in one cell, separated with a comma.
For example in cell A1 all the selected names: Tim, Miranda, Laura
Those cells are the criteria for an Access query (where clause).
I open MS Query and add the following where clause to the query and define the parameters:
Where (Instr(?, [name])>0 And Instr(?, [number])>0 And Instr(?, [city])>0 And Instr(?, [phone])>0 And Instr(?, [email])>0)
It works quite well, however if one of the parameter fields is empty (for example the user didn't select any city) the query returns all lines, where city is empty instead of ignoring that clause in this case.
How do I solve this? Perhaps there is another solution using VBA and dynamic SQL.
Note: I have to use Excel for the listboxes instead of Access formulas because the tool shall also be used by persons who do not have access to the database.
From my experience, it may be returning null in some cases and affecting your comparison in the clause.
what happens when you try the len function:
See the code change above. Sorry, saw your update, I just need to get a grip on the problem. Do you want all records including those that have "empty" cities? But I thought you wanted it to skip those? Another way I search for this is - NOT ISNULL([CITY]) . I work in an environment with a LOT of Access databases and they are quirky!