date Filter on form (3 months, non consecutive)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Neruda
    New Member
    • Mar 2017
    • 72

    date Filter on form (3 months, non consecutive)

    Hi,
    would like to filter a form with a form filter, the form has 12 buttons (12 months) and would like to retrieve records depending on which button is pressed.
    This filter example works, it shows records from Jan, Feb, and Apr 2021 but I don't get why it shows them all. Should't it show just one month because I used OR?


    Month([DateProcessed])=1 AND Year(DateProces sed)=2021 OR Month([DateProcessed])=2 AND Year(DateProces sed)=2021 OR Month([DateProcessed])=4 AND Year(DateProces sed)=2021
  • isladogs
    Recognized Expert Moderator Contributor
    • Jul 2007
    • 483

    #2
    Add brackets around each section to clarify what the code is doing

    Code:
    (Month([DateProcessed])=1 AND Year(DateProcessed)=2021) 
    OR (Month([DateProcessed])=2 AND Year(DateProcessed)=2021) 
    OR (Month([DateProcessed])=4 AND Year(DateProcessed)=2021)
    Now can you see why it will show results for each of the months listed

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Hi Neruda.

      I think what you're missing in your appreciation of how the SQL WHERE clause works is that it :
      1. ISN'T - an overall description of the logic of which records to get such as :
        Get me all records WHERE A AND/OR all records WHERE B.
      2. IS - a description of the logic for each record :
        Get me all records WHERE (For each record) A AND/OR B.

      In your case, assuming I were to choose months Jan & Apr (Forgetting about Year for now.), then I would choose every record which was Jan AND every record which was Apr, because - at an individual record level - Jan OR Apr evaluated to True.

      Does that make the logic clearer?

      Comment

      Working...