Is there a way to check if the this year is a leap year with VBA?

smercer

Registered User.
Local time
Tomorrow, 09:25
Joined
Jun 14, 2004
Messages
442
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!!!
 
Code:
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
 
Thanks so much for that Miles.

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

Code:
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
 
I don't know as I've never used - and most likely never will - Access Data Pages. :(
 
SJ McAbney said:
I don't know as I've never used - and most likely never will - Access Data Pages. :(

Nether have I, Until now....

Thanks anyway
 
Code:
if year(now) mod 4 = 0 then msgbox "Its a leap year!"
'---- or
isdate("29 Feb " & year(now))
 

Users who are viewing this thread

Back
Top Bottom