I am trying to create a query that prompts the user to enter a single character or hit enter for all. I am able to do this with this query:
Like [Enter Zone (1, 2, 3, 4, 5, 20, 21, P, A, F, C, T, B, E, S) or Hit Enter for All] & "*"
However, when the user says "OK" and requests for all, I need the query to NOT include 20 and 21.
I tried adding Or Not Like ("20", "21")
or (Not Like "20" And Not Like "21")
at the end but I get an error.
I feel like this is something simple but I can't figure out the order.
Thanks in advance.
Using numeric criteria with choices like 2, 20, 21 means cannot concatenate with wildcard so 20 and 21 are not retrieved when 2 is selected.
Using a popup input prompt with that long statement in query will look messy.
LIKE IIf([Enter Zone (1, 2, 3, 4, 5, 20, 21, P, A, F, C, T, B, E, S) or Hit Enter for All] <> "", [Enter Zone (1, 2, 3, 4, 5, 20, 21, P, A, F, C, T, B, E, S) or Hit Enter for All], "*")
Using a reference to form control a little less messy:
LIKE IIf(NOT [Forms!formname!controlname] IS NULL, [Forms!formname!controlname], "*")
Either will allow returning records matching value entered or returning all if nothing entered. This will not solve the issue of excluding 20 and 21 from all - for that I recommend using a VBA solution that builds filter criteria and applies to form or report.