Ramon,
The problem is that there are no functions that define a month or week the
way you want to define them. So I wrote a series of three function
fnMyMonth, fnMyWeek, and fnFirstSunday (see below-watch out for line breaks)
so that you can determine what Month, and Week your dates are in. Save these
functions in a code module, then write a query that would look something like
(assumes your table has a PK field called ID):
SELECT Year([Start Date]) as CallYear,
fnMyMonth([Start Date]) as CallMonth,
fnMyWeek([Start Date]) as CallWeek,
Count(ID) as CallsPerWeek
FROM yourTable
GROUP BY Year([Start Date]),
fnMyMonth([Start Date]),
fnMyWeek([Start Date])
If you are really only concerned with the first week of each month, you can
add a WHERE clause to restrict the CallWeek value to 1.
HTH
Dale
Public Function fnMyMonth(ByVal SomeDate As Date) As Integer
Dim dtFirstSunday As Date
dtFirstSunday = fnFirstSunday(SomeDate)
fnMyMonth = Month(SomeDate) + (SomeDate < dtFirstSunday)
End Function
Public Function fnMyWeek(ByVal SomeDate As Date) As Integer
Dim dtFirstSunday As Date
dtFirstSunday = fnFirstSunday(SomeDate)
'If the first Sunday is after the date passed, then the date
'falls in the previous months week count
If dtFirstSunday > SomeDate Then
dtFirstSunday = fnFirstSunday(DateAdd("m", -1, SomeDate))
End If
fnMyWeek = Int(DateDiff("d", dtFirstSunday, SomeDate) / 7) + 1
End Function
Public Function fnFirstSunday(ByVal SomeDate As Date) As Date
'Accepts a date and returns the first Sunday of that month
Dim intLoop As Integer
'The first Sunday has to fall sometime in the first 7 days of the month
For intLoop = 1 To 7
If Weekday(DateSerial(Year(SomeDate), Month(SomeDate), intLoop),
vbSunday) = 1 Then
fnFirstSunday = DateSerial(Year(SomeDate), Month(SomeDate), intLoop)
Exit Function
End If
Next
End Function