Date reference in an IIF statement

P

Presto

The following statement works well. It is the default value for a payment.
However, every year I have to go in and change the year.

=(IIf(Date()>#3/31/2010#,"$45.00","$40.00"))

I would like to have it look at 3/31/(of whatever year it is) so I dont have
to reprogram this every year. How do I change the date reference?

Thanks in advance.
 
F

fredg

The following statement works well. It is the default value for a payment.
However, every year I have to go in and change the year.

=(IIf(Date()>#3/31/2010#,"$45.00","$40.00"))

I would like to have it look at 3/31/(of whatever year it is) so I dont have
to reprogram this every year. How do I change the date reference?

Thanks in advance.

=IIf(Date() >DateSerial(Year(Date()),3,31),"$45.00","$40.00")
 
L

Linq Adams via AccessMonster.com

= IIF(Month(Date) & "/" & Day(Date)> #3/31#, "$45.00","$40.00")
 
D

Douglas J. Steele

Sorry, Linq, but that won't work in October, November or December since
you're using string comparisons.
 
J

John W. Vinson

The following statement works well. It is the default value for a payment.
However, every year I have to go in and change the year.

=(IIf(Date()>#3/31/2010#,"$45.00","$40.00"))

IIF(Date() > #3/31#, "$45.00", "$40.00")

will work. If you don't specify a year in a date literal, Access fills in the
current year for you.
 
L

Linq Adams via AccessMonster.com

Actually, Doug, it did when I tested it for all months of the year, including
Oct/Nov/Dec. My experience has been if it looks like a date Access treats it
like a date.
 
D

Douglas J. Steele

Sorry, I missed the fact that you were comparing to #3/31#, not "3/31"

Yes, it should work, but using DateSerial is far safer than using implicit
data coercion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top