Search code examples
ms-accessms-office

How can I combine date with WHERE clause


I have a WHERE condition and i want filter two reports in first I want to onlu have items from 2020 year and in the other from 2019 I m trying to write it like this:

[UMOWY]![data_wygasniecia]>#01.01.2019#<#01.01.2020#

AND In 2020

[UMOWY]![data_wygasniecia]>#01.01.2020#<#01.01.2021#

But it doesnt work, my table is UMOWY and and the column name is data_wygasniecia the date is stored in date format. Can you please help?

https://i.sstatic.net/9reb5.jpg photo where how where i try


Solution

  • Use the correct syntax for date expressions:

    [UMOWY]![data_wygasniecia] Between #2019/01/01# And #2019/12/31#
    

    or, if a time component is present:

    [UMOWY]![data_wygasniecia] >= #2019/01/01# 
    And
    [UMOWY]![data_wygasniecia] < #2020/01/01#
    

    or, if the recordset isn't too large:

    Year([UMOWY]![data_wygasniecia]) = 2019