Date calculation issue

  • Thread starter Thread starter Candiz
  • Start date Start date
C

Candiz

I have two fields. Field1 is to enter a date such as 11/27/2004. I want
Field2 to calculate to be exactly three months after resulting in 02/27/2005
in mmddyyyy format. Note that the day (dd) must be the same.



How do I accomplish this by code?
 
Candiz said:
I have two fields. Field1 is to enter a date such as 11/27/2004. I
want Field2 to calculate to be exactly three months after resulting
in 02/27/2005 in mmddyyyy format. Note that the day (dd) must be
the same.

How do I accomplish this by code?

You don't need code, if this is happening in a form. Set the
ControlSource property of Field2 to

=DateAdd("m", 3, [Field1])

You can set the Format property of Field2 to display the date value
however you prefer to see it.

However, your requirement that the day must always be the same is not
logically possible. Suppose that Field 1 is 8/31/2004. What should
Field2 be? There is no such date as 11/31/2004. The DateAdd function
deals with this problem by returning 11/30/2004 for 8/31/2004, just as
it does for 8/30/2004. If that's not what you want, you'll have to
specify your desired behavior in some other terms than just "add three
months to Field1".
 
Dirk
Superb. Thanks for the tip!
Dirk Goldgar said:
Candiz said:
I have two fields. Field1 is to enter a date such as 11/27/2004. I
want Field2 to calculate to be exactly three months after resulting
in 02/27/2005 in mmddyyyy format. Note that the day (dd) must be
the same.

How do I accomplish this by code?

You don't need code, if this is happening in a form. Set the
ControlSource property of Field2 to

=DateAdd("m", 3, [Field1])

You can set the Format property of Field2 to display the date value
however you prefer to see it.

However, your requirement that the day must always be the same is not
logically possible. Suppose that Field 1 is 8/31/2004. What should
Field2 be? There is no such date as 11/31/2004. The DateAdd function
deals with this problem by returning 11/30/2004 for 8/31/2004, just as
it does for 8/30/2004. If that's not what you want, you'll have to
specify your desired behavior in some other terms than just "add three
months to Field1".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top