Does anybody know of any code to calculate whether a certain year is a leap
year, in Access VBA?
fredg - 30 Mar 2005 02:04 GMT
> Does anybody know of any code to calculate whether a certain year is a leap
> year, in Access VBA?
Check for whether 2/29/xxxx is a date:
In the debug window
? IsDate(#2/29/2004#) returns True
? IsDate(#2/29/2005#) returns an error.

Signature
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Dirk Goldgar - 30 Mar 2005 06:47 GMT
>> Does anybody know of any code to calculate whether a certain year is
>> a leap year, in Access VBA?
[quoted text clipped - 3 lines]
> ? IsDate(#2/29/2004#) returns True
> ? IsDate(#2/29/2005#) returns an error.
You can use that method without raising an error.
?IsDate("2/29/2004")
True
?IsDate("2/29/2005")
False

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
Ken Snell [MVP] - 30 Mar 2005 02:05 GMT
Here is a function that will test this for you:
Public Function IsThisALeapYear(intYearToTest As Integer) As Boolean
' Returns True if intYearToTest is a leap year; False if not
IsThisALeapYear = (DateSerial(intYearToTest, 3, 1) <>
DateSerial(intYearToTest, 2, 29))
End Function

Signature
Ken Snell
<MS ACCESS MVP>
> Does anybody know of any code to calculate whether a certain year is a
> leap
> year, in Access VBA?
Tim Ferguson - 30 Mar 2005 18:44 GMT
> any code to calculate whether a certain year is a leap
> year
IsLeap = (Month(DateSerial(YearNum, 2,29))=2)
or the independent way:
IsLeap = (((YearNum Mod 4)=0) And _
((YearNum Mod 100)>0) _
) Or _
((YearNum Mod 400)=0)
Hope that helps
Tim F