Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

Code to calculate a leap year

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wayne - 30 Mar 2005 01:49 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.