Here's a function that should work. You pass it the two dates in the range, and it will return the average employees in the range.
The call would look like:
Msgbox GetAvgEmp("1/1/01", "1/7/01")
Private Function GetAvgEmp(atDate1 As Date, atDate2 As Date) As Double
Dim db As Database
Dim rst As Recordset
Dim sSql As String
Dim tDateIndex As Date
Dim lEmpCount As Long
If atDate1 > atDate2 Then
MsgBox "The first date must be earlier than the second date.", vbExclamation
Exit Function
End If
Set db = CurrentDb
'--loop through the dates - inclusively
For tDateIndex = atDate1 To atDate2
sSql = "Select Count(EmpId) as NumEmps From tblEmps " & _
"Where StartDate <= #" & tDateIndex & "# And " & _
"(TermDate >= #" & tDateIndex & "# or TermDate Is null)"
Set rst = db.OpenRecordset(sSql)
If Not rst.EOF Then
If Not IsNull(rst!NumEmps) Then
'--accumulate the number of employees lEmpCount = lEmpCount + rst!NumEmps
End If
End If
rst.Close
Set rst = Nothing
Next
Set db = Nothing
'--divide the number of employees by the number of days in the date range
'--need to add 1 to thedate difference since we are including both days in the range
GetAvgEmp = lEmpCount / (atDate2 - atDate1 + 1)
End Function