View Full Version : Is there a way to check if the this year is a leap year with VBA?


smercer
11-24-2004, 02:21 AM
Hi all

I am creating a calender in the Access Data Pages and I was wondering if there is a way to check for whether the current year is a leap year with VBA?

Thanks for your help!!!

Mile-O
11-24-2004, 02:29 AM
Public Function IsLeapYear(ByVal intYear As Integer) As Boolean
On Error GoTo Err_IsLeapYear
Dim dteTemp As Date
dteTemp = DateSerial(intYear, 2, 29)
If Day(dteTemp) = 29 Then IsLeapYear = True
Exit Function
Err_IsLeapYear:
IsLeapYear = False
End Function

smercer
11-24-2004, 04:07 AM
Thanks so much for that Miles.

I have modified your code so that it is like this:

Function Twenty_Ninth_Date()
On Error GoTo Err_IsLeapYear
Dim dteTemp As Date
Dim IsLeapYear As Boolean

dteTemp = DateSerial(Year(Date), 2, 29)

If Day(dteTemp) = 29 Then IsLeapYear = True

Err_IsLeapYear:
If Month(Date) <> 2 Or IsLeapYear = True Then
Twenty_Ninth_Date = DateSerial(Year(Date), Month(Date), 29)
End If

End Function

But this function and the functions for 30th and 31st dates are done in a simalar way. they are then set as the query criteria, however the problem I am having is when the page is viewed in a browser, I get errors, but when viewed in the page view in Access it shows Ok.

Is there something I am doing wrong?

Thanks for your help

Mile-O
11-24-2004, 04:16 AM
I don't know as I've never used - and most likely never will - Access Data Pages. :(

smercer
11-24-2004, 04:19 AM
I don't know as I've never used - and most likely never will - Access Data Pages. :(

Nether have I, Until now....

Thanks anyway

ecniv
11-24-2004, 06:26 AM
if year(now) mod 4 = 0 then msgbox "Its a leap year!"
'---- or
isdate("29 Feb " & year(now))