It would be easier to do this in a function. Paste the
following into a regular module:
Note: No error handling:
Public Function NumberOfDaysInMonth(varDate)
If IsDate(varDate) Then
Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer
Dim dteLastDayOfMonth As Date
intYear = DatePart("yyyy", DateAdd("m", 1, varDate))
intMonth = DatePart("m", DateAdd("m", 1, varDate))
intDay = 1
dteLastDayOfMonth = DateSerial(intYear, intMonth,
intDay) - 1
NumberOfDaysInMonth= Day(dteLastDayOfMonth)
Else
NumberOfDaysInMonth= Null
End If
End Function
The logic goes: Add a month to he day in question, then
get the first of the month. Subtract one day, then figure
out the day part. This method works even for leap years.
Once you have this in a module, you can use it in a query.
DaysInMonth: NumberOfDaysInMonth([MyDateField])
Chris Nebinger
Chris Nebinger