Here is my whole module
I call these modules thru a query that pulls the dates from a crosstab query
the crosstab goes:
cadetid Date of Enty Exited Boot Camp
1 2006-05-05 2006-12-20
33 2006-08-15 2007-06-11
....
....
I select the month thru a form that I type the year and numeric month
The function DatesofService is working correctly and so is the IsEnrolled
Function, now the DaysofService function is not. The function returns the
number of days -1 for the entire month, ie Jun has 30 days, the function
returns 29 days for all records
Could you go thru and find the error, because I can not.
PS:The response = msgbox() is so that I could check the what data is being
used.
Public Function NumofDays(Month As Integer) As Integer
On Error GoTo Error_NumofDays
Select Case Month
Case 1
NumofDays = 31
Case 2
NumofDays = 28
Case 3
NumofDays = 31
Case 4
NumofDays = 30
Case 5
NumofDays = 31
Case 6
NumofDays = 30
Case 7
NumofDays = 31
Case 8
NumofDays = 31
Case 9
NumofDays = 30
Case 10
NumofDays = 31
Case 11
NumofDays = 30
Case 12
NumofDays = 31
Case Else
NumofDays = 31
End Select
Exit_NumofDays:
Exit Function
Error_NumofDays:
MsgBox Err.Description
Resume Exit_NumofDays
End Function
Public Function IsEnrolled(dEntry As Date, dExit As Variant, ReqMon As
Integer, ReqYear As Integer) As Boolean
On Error GoTo Err_IsEnrolled
Dim dReqDate
dReqDate = DateValue(DateSerial(ReqYear, ReqMon, 1))
'response = MsgBox(dReqDate & " " & dEntry & " " & dExit, vbOKOnly)
dStartofMonth = DateValue(DateSerial(ReqYear, ReqMon, 1))
dEndofMonth = DateValue(DateSerial(ReqYear, ReqMon, NumofDays(ReqMon)))
'response = MsgBox(dStartofMonth & " " & dEntry & " " & dExit, vbOKOnly)
If IsDate(dExit) = False Then dExit = dEndofMonth
If (Format(dEntry, "yyyy mm") <= Format(dReqDate, "yyyy mm")) = True
Then
'response = MsgBox(dEntry & " " & dReqDate, vbOKOnly, "dEntry <=
dReqDate")
If (Format(dReqDate, "yyyy mm") <= Format(dExit, "yyyy mm")) =
True Then
'response = MsgBox(dEntry & " " & dReqDate & " " & dExit,
vbOKOnly, "dEntry <= dReqDate <= dExit")
IsEnrolled = True
Else
IsEnrolled = False
End If
Else
IsEnrolled = False
End If
Exit_IsEnrolled:
Exit Function
Err_IsEnrolled:
MsgBox Err.Description
Resume Exit_IsEnrolled
End Functio
Public Function CalcDaysofService(dEntry As Date, dExit As Variant, ReqMon
As Integer, ReqYear As Integer) As Integer
On Error GoTo Err_CalcDaysofService
Dim dEndofMonth As Date
Dim dStartofMonth As Date
Dim iFirstDay As Integer
Dim iLastDay As Integer
iFirstDay = 1
iLastDay = NumofDays(ReqMon)
dStartofMonth = DateValue(DateSerial(ReqYear, ReqMon, 1))
dEndofMonth = DateValue(DateSerial(ReqYear, ReqMon, NumofDays(ReqMon)))
'response = MsgBox(dStartofMonth & " " & dEntry & " " & dExit, vbOKOnly)
If IsDate(dExit) = False Then
dExit = dEndofMonth
End If
If (Year(dEntry) = ReqYear) = True And (Month(dEntry) = ReqMon) = True
Then
If Day(dEntry) >= 1 Then
iFirstDay = Day(dEntry)
Else
iFirstDay = 1
End If
iFirstDay = 1
End If
'response = MsgBox(iFirstDay, vbOKOnly, "First Day")
If (Year(dExit) = ReqYear) = True And (Month(dExit) = ReqMon) = True Then
If Day(dExit) <= NumofDays(ReqMon) Then
iLastDay = Day(dExit)
Else
iLastDay = NumofDays(ReqMon)
End If
iLastDay = NumofDays(ReqMon)
End If
'response = MsgBox(iLastDay, vbOKOnly, "Last Day")
CalcDaysofService = diff2dates2("d", DateValue(DateSerial(ReqYear,
ReqMon, iFirstDay)), DateValue(DateSerial(ReqYear, ReqMon, iLastDay)))
Exit_CalcDaysofService:
Exit Function
Err_CalcDaysofService:
MsgBox Err.Description
Resume Exit_CalcDaysofService
End Function
Public Function DatesofService(iDaysofService As Integer, dDoE As Date,
dDoExit As Variant, ReqMon As Integer, ReqYear As Integer) As Variant
On Error GoTo Err_DatesofService
dStartofMonth = DateValue(DateSerial(ReqYear, ReqMon, 1))
dEndofMonth = DateValue(DateSerial(ReqYear, ReqMon, NumofDays(ReqMon)))
If IsDate(dDoExit) = False Then dDoExit = dEndofMonth
If iDaysofService < NumofDays(ReqMon) Then
If (Year(dDoE) = ReqYear) = True And (Month(dDoE) = ReqMon) = True
Then
iFirstDay = Day(dDoE)
Else
iFirstDay = 1
End If
'response = MsgBox(iFirstDay, vbOKOnly, "First Day")
If (Year(dDoExit) = ReqYear) = True And (Month(dDoExit) = ReqMon) =
True Then
iLastDay = Day(dDoExit)
Else
iLastDay = NumofDays(ReqMon)
End If
DatesofService = iFirstDay & " - " & iLastDay & " " &
Format(dEndofMonth, "mmm")
Else
DatesofService = "1 - " & NumofDays(ReqMon) & " " &
Format(dEndofMonth, "mmm")
End If
Exit_DatesofService:
Exit Function
Err_DatesofService:
MsgBox Err.Description
Resume Exit_DatesofService
End Function