Try this:
= ([tstudentclass subform1].[Form]![FundingSource] = 1 And [tstudentclass
subform1].[Form]![EndDate] < Date() And IsNull([tstudentclass
subform1].[Form]![DropDate]))
The expression should evaluate to True if all of the three sub-expressions
evaluate to True. Consequently the check box will be checked or unchecked as
appropriate.
You say "EndDate is earlier than today" should be true, so I've changed the
expression to < Date(). The Date function returns the date/time at midnight
at the start of the current day, whereas the Now function returns the current
date and time. If the EndDate value was today at or before the current time
of day, bearing in mind all date/time values include some time of day, even
if its zero, i.e. midnight at the start of the day, the <=Now() would
evaluate to True, but the value would not be "earlier than today".
Arising from this if you want to test for a date time value being today then
don't test for equality. If the value includes a non-zero time of day (which
might not show if the value is formatted as date only) then MyDate = Date()
will evaluate to False as the time of day returned by Date is zero. The best
way to test for values matching today's date is to test for the value being
on or after today and before the day after today, MyDate >= Date() And MyDate
< Date() + 1. Whatever the time of day in MyDate, from 00:00:00 to 23:59:59,
will be before midnight at the start of tomorrow. Another way would be to
use the DateValue function, DateValue(MyDate) = Date(). This possibility of
dates including unseen times if day frequently catches people out when
testing for dates within a range:
WHERE MyDate BETWEEN #07/04/2005# AND #12/25/2005#
will evaluate to false if MyDate is Christmas Day, but includes a non-zero
time of day, whereas:
WHERE MyDate >= #07/04/2005# AND MyDate < #12/25/2005# + 1
would evaluate to True for any date/time value from midnight at the start of
4th July this year to 23:59:59 on Christmas Day this year.
Where you'd gone wrong with the nested IIF functions BTW was in including
the Boolean AND operators. To nest IIF functions you don't need Boolean
operations; instead you use one function as the 'not true' argument of the
previous one, so if the first evaluates to False it evaluates the nest one
and so on down the line until one evaluates to True.
Also you've used the literal strings "YES" and "NO". In circumstances like
this use the Boolean values TRUE and FALSE (without quotes). Access does use
Yes and No to express Boolean values, but its better to stick with the
standard forms, TRUE and FALSE. Sometimes you'll see -1 and 0 used for TRUE
and FALSE. This is how Access implements Boolean values, but its not a good
idea to use these integer values. Relying on the implementation is regarded
as bad programming practice.
John said:
Hello,
I have a check box control on my form and would like to create an expression:
In the form I have 3 bound controls( Founding Source, EndDate, DropDate)
In my check box control I would like to see a check mark whenever the
funding source = 1, and EndDate is earlier than today, and the DropDate is
empty or no dropdate. I have the following expression:
=IIf([tstudentclass subform1].[Form]![FundingSource]=1,"YES" And
IIf([tstudentclass subform1].[Form]![EndDate]<=(Now()),"YES","NO" And
IIf([tstudentclass subform1].[Form]![DropDate]=null,"YES"))).
For some reason, the fundingsource works but not the other two??? Any idea
why?? OR a better solution would be great.
John