0
votes

I have an ACCESS database that has a table with date as one of the fields. I can create a form that allows the user to enter a start date and end date and then use those in a query to filter the date for only records between those dates. But I would like to make the end date optional so if the user would only enter the start date the query would return on records greater than that date. I am trying to do this with one query and without getting into VBA but not sure if this can be done.

I tried something like this but it did not work...I got error message saying the syntax was not correct or I got no results at all.

In the date field criteria I tried IIF(isNull([Forms]![frmdateselect]![enddate]), (>=DateValue([Forms]![frmdateselect]![startdate])), ((>=DateValue([Forms]![frmdateselect]![startdate])) AND (<=DateValue([Forms]![frmdateselect]![enddate]))))

Any help would be great

1

1 Answers

1
votes

Have you tried replacing the IsNUll with the Nz function?

IIF(Nz([Forms]![frmdateselect]![enddate]),0),
([Forms]![frmdateselect]! [enddate]),
(>=DateValue([Forms]![frmdateselect]![startdate])), 
((>=DateValue([Forms]![frmdateselect]![startdate])) AND 
(<=DateValue([Forms]![frmdateselect]![enddate]))))