date criteria as NULL

Mr.K

Registered User.
Local time
Today, 13:47
Joined
Jan 18, 2006
Messages
104
I have a form with two controls: DateFrom & DateTo
I want to filter based on those criteria but when the criteria is ommitted (NULL) I want to display all.

In case of other controls I have an SQL as follows:
... WHERE (tblClassesOffered.Course = Forms!frmClassReport.class Or Forms!frmClassReport.class Is Null)

But with the dates controls the best I could come up with is:
...Between IIf(IsNull([Forms]![frmClassReport].[DateFrom]),#1/1/1900#,[Forms]![frmClassReport].[DateFrom]) And IIf(IsNull([Forms]![frmClassReport].[DateTo]),#1/1/3000#,[Forms]![frmClassReport].[DateTo]) Or Is Null

However that solution is kind of ugly becasue instead of wild cards (I couldn't make them work) I'm using those made up dates and I also wish not to use the IIF if possible (like the first statement).
 
Last edited:
WHERE ([DateField] between [Forms]![frmClassReport].[DateFrom] and [Forms]![frmClassReport].[DateTo] or [Forms]![frmClassReport].[DateFrom] is null or [Forms]![frmClassReport].[DateTo] is null)


When either [DateFrom] or [DateTo] is null, all records will be returned.

^
 

Users who are viewing this thread

Back
Top Bottom