Gustav Brock
Gustav at cactus.dk
Fri Jul 18 04:01:03 CDT 2008
Hi Darryl This can be done a lot simpler. The trick is the day of zero which forces DateSerial to return the date before the first of the month. <code> Public Function DaysInMonth(ByVal datDate As Date) As Integer ' Returns count of days of month of datDate. ' 2005-01-06. Cactus Data ApS, CPH. Dim intDays As Integer intDays = Day(DateSerial(Year(datDate), Month(datDate) + 1, 0)) DaysInMonth = intDays End Function </code> /gustav >>> Darryl.Collins at coles.com.au 18-07-2008 03:15 >>> Hi Darren, Did you try Drews suggestion? >From Access Help: '======================================================== DateSerial, Day, Month, and Year Function Examples The following example uses the DateSerial function together with the Year, Month, and Day functions to return the number of days in a month. You can pass either a date or a string to the DaysInMonth function. Function DaysInMonth(dteInput As Date) As Integer Dim intDays As Integer ' Add one month, subtract dates to find difference. intDays = DateSerial(Year(dteInput), _ Month(dteInput) + 1, Day(dteInput)) _ DateSerial(Year(dteInput), _ Month(dteInput), Day(dteInput)) DaysInMonth = intDays Debug.Print intDays End Function The following Sub procedure shows several different ways that you might call the DaysInMonth function. Sub CallDaysInMonth() Dim intDays As Integer intDays = DaysInMonth(#4/1/96#) intDays = DaysInMonth("4-1-96") intDays = DaysInMonth("April 1, 1996") End Sub '================================================================