Hello,
This is driving me slightly insane, so I would really appreciate any help you could offer.
I am designing a query based on a form and I am trying to get the correct criteria expression to return records between an earliest year and a latest year, including if one or other of them (or both) is left blank.
I have two text boxes on the form (QBF_Form), which are named [WhatEarliestYear] and [WhatLatestYear] and they are set up as Long Integers.
Someone suggested that I enter the [Year] field into two separate columns on my query design view and put the following expressions in:
IIF(IsNull([Forms]![QBF_Form]![WhatLatestYear]), [Year], <=[Forms]![QBF_Form]![WhatLatestYear])
IIF(IsNull([Forms]![QBF_Form]![WhatEarliestYear]), [Year], >=[Forms]![QBF_Form]![WhatEarliestYear])
This makes complete sense to me. However, I cannot get even one of these IIF statements to work. If nothing is entered in either the [WhatEarliestYear] or [WhatLatestYear] boxes on the form, all records are returned, which is exactly what I want. However, if one year is entered in one box and the other left blank, then no records are returned, when what I want is for all records in or after an earliest year entered to come back, or all records in or before a latest year to come back.
Any suggestions?
Thanks in advance.
This is driving me slightly insane, so I would really appreciate any help you could offer.
I am designing a query based on a form and I am trying to get the correct criteria expression to return records between an earliest year and a latest year, including if one or other of them (or both) is left blank.
I have two text boxes on the form (QBF_Form), which are named [WhatEarliestYear] and [WhatLatestYear] and they are set up as Long Integers.
Someone suggested that I enter the [Year] field into two separate columns on my query design view and put the following expressions in:
IIF(IsNull([Forms]![QBF_Form]![WhatLatestYear]), [Year], <=[Forms]![QBF_Form]![WhatLatestYear])
IIF(IsNull([Forms]![QBF_Form]![WhatEarliestYear]), [Year], >=[Forms]![QBF_Form]![WhatEarliestYear])
This makes complete sense to me. However, I cannot get even one of these IIF statements to work. If nothing is entered in either the [WhatEarliestYear] or [WhatLatestYear] boxes on the form, all records are returned, which is exactly what I want. However, if one year is entered in one box and the other left blank, then no records are returned, when what I want is for all records in or after an earliest year entered to come back, or all records in or before a latest year to come back.
Any suggestions?
Thanks in advance.