Skip to content
Advertisement

IIF statement to filter Access Query with checkbox

I’m working on a search form based off a single table. I’m working primarily in the query design view. I’d like to have a checkbox on the form so if it is checked (true) it will only return records where the setID is Null. If unchecked (false) it will return all records regardless of if there is a value in setID or not. Looking for a bit of help writing the iif statement (I’m very, very new to this).

source table: Inventory field: setID form: frmSearchInventory form control: ckExcludeSet

iif(Forms!frmSearchInventory!ckExcludeSets = true, Inventory.SetID is Null, Inventory.SetID is not Null)

Close? Also, in the query design view, do I need anything additional in the criteria row? Many thanks!

Advertisement

Answer

For a dynamic query, calculate a field that returns SetID or a value in lieu of null: Nz(SetID, "N")

Then criteria under that calculated field:

LIKE IIf(Forms!frmSearchInventory!ckExcludeSets, "N", "*")

An unbound checkbox can be set for triple state. Make sure yours allows only True or False, never Null – set TripleState property to No. Set DefaultValue property to either True or False.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement