Results 1 to 8 of 8
  1. #1
    Noah4x4 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5

    DateAdd error in MS Office 2010

    I have two controls, [Inception Date] and [Expiry Date] for for an insurance policy application. So Insert Inception Date and the Expiry Date is calculated. I am here using (as +365 days isn't always correct).



    Dim Tempdate
    Tempdate = [Inception Date]
    [Expiry Date] = DateAdd ("Yyyy", 1, "Tempdate")

    Enter 1 March 2011 and this returns 29 Feb 2012.
    At first glance, this seems to be correct for an insurance policy as expiry is always one day befor renewal. However;
    Enter 1 March 2012 and it now returns 1 March 2013.

    I have tried
    [Expiry Date] = DateAdd ("Yyyy", 1, "Tempdate") - 1
    Also
    [Expiry Date] = (DateAdd ("Yyyy", 1, "Tempdate") - 1)

    An each time when I enter 1 march 2012 and it returns 1 March 2013. Surely one of these should result in a day earlier? I thought DateAdd handled leap years OK? What am I missing?

    Help please? BTW, I am using the (date picker) - is that the same as the 'calendar control', mentioned in the previous thread as no longer supported? Does it hence have a bug? If yes, is ait available under Date/Time properties?
    Last edited by Noah4x4; 03-12-2011 at 04:34 AM. Reason: Further information

  2. #2
    Noah4x4 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    BTW, I am using the 'date picker' tool. Is there some issue with this (see previous thread)? If yes, why is it still a feature of an out of the box copy of Access 2010 purchased only last week?

  3. #3
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Wouldn't this line...

    [Expiry Date] = DateAdd ("Yyyy", 1, "Tempdate")

    be

    [Expiry Date] = DateAdd ("Yyyy", 1, #Tempdate#)

    Just a thought.

  4. #4
    Noah4x4 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    Tried that
    [Expiry Date] = DateAdd ("Yyyy", 1, #Tempdate#)

    The # signs create a compile error - am sure it is "Tempdate" (am also following code guidelines in a book)

    But what I completely don't understand is why DateAdd ("Yyyy", 1, "Tempdate") returns 29th Feb 2012 when Tempdate is 1st March 2011, yet returms 1st March 2013 if Tempdate is 1st March 2012.

    I can see one is a leap year, but surely if the first returns 29th Feb the second should return 28th Feb if adding a calender year. Else what is the advantage over simply adding + 365 to Date()?

    One returns a day less. I thought DateAdd auto-adjusted for leap years?

  5. #5
    Noah4x4 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    Doh....I am an idiot

    Worked it out now.

    2013 isn't a leap year although 2012 is...arrrgggh.my head hurts from too many run time errors

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great! I guess you are now ready to use the Thread Tools and mark this thread as Solved, yes?

  7. #7
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Quote Originally Posted by Noah4x4 View Post
    I thought DateAdd auto-adjusted for leap years?
    Yes - I believe it does (or should).

  8. #8
    Noah4x4 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Mar 2011
    Posts
    5
    It does!

    What I could not get my head around was that if an insurance policy started on 1st March, it always has a renewal date of 1st March. So if incepted in 2011, it expires on 29th February, and if incepted in 2012 it expires on 28th Feb...fair enough... always the day before.

    But a policy incepted on 29th February 2012 and another incepted 1st March 2012 must BOTH have the same renewal date of 1st March 2013 and an expiry date of 28th February.

    My brain hurt trying to work out why the expiry date result for both was exactly the same when normal mathematical logic suggested one should be a day earlier (reason is 2013 isn't a leap year and 29th february doesn't exist)......doh!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2010 - Error Code 438 Problem
    By Lexus350 in forum Access
    Replies: 5
    Last Post: 03-03-2011, 11:46 PM
  2. Replies: 0
    Last Post: 01-22-2011, 08:08 AM
  3. Office 2010, 64 bit crashed
    By gppkuntz in forum Access
    Replies: 2
    Last Post: 12-21-2010, 06:28 PM
  4. Office 2010 and linked table manager Help
    By bobfin in forum Access
    Replies: 8
    Last Post: 08-05-2010, 07:15 PM
  5. Replies: 1
    Last Post: 03-02-2010, 03:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums