Search code examples
sqlms-accesscriteriams-access-2016

MS Access: If option button is selected, use a criteria, otherwise return all rows


I have a table with a field called job. I have a form with an option button. If the option button is not selected, I want to return all rows. However, if the option button is selected, I want to return all rows that do not begin with "RWK". How can I achieve this?


Solution

  • This should do it:

    SELECT * FROM myTable 
    WHERE Forms!myForm!myOptionButton.Value = 0 
       OR job NOT LIKE 'RWK*'
    

    Boolean logic. If the option button is off, the WHERE clause is always true.