Hello,
Up until today this coding has been working perfectly. I am using it with MS Access 2010 in 2003 mode because that is how old the database is. The dates are pulled from a form that uses text boxes to enter dates. The text boxes are formatted to Short Date and they work great. The problem is I am all of a sudden getting an overflow error. If I type the dates directly into the query that is using the module it will work just fine. But pulling it from the form I get the error. Here is the code. Any and all help will be appreciated.
PS: The error highlights on the last line beginning with "WorkDays" before End Function. If I hover over BegDate I see 05/26/207.
Function Work_Days(BegDate As Variant, EndDate As Variant) As Integer
' Note that this function does not account for holidays.
Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer
BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
WholeWeeks = DateDiff("w", BegDate, EndDate)
DateCnt = DateAdd("ww", WholeWeeks, BegDate)
EndDays = 0
Do While DateCnt < EndDate
If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat" Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = WholeWeeks * 5 + EndDays
End Function
Up until today this coding has been working perfectly. I am using it with MS Access 2010 in 2003 mode because that is how old the database is. The dates are pulled from a form that uses text boxes to enter dates. The text boxes are formatted to Short Date and they work great. The problem is I am all of a sudden getting an overflow error. If I type the dates directly into the query that is using the module it will work just fine. But pulling it from the form I get the error. Here is the code. Any and all help will be appreciated.
PS: The error highlights on the last line beginning with "WorkDays" before End Function. If I hover over BegDate I see 05/26/207.
Function Work_Days(BegDate As Variant, EndDate As Variant) As Integer
' Note that this function does not account for holidays.
Dim WholeWeeks As Variant
Dim DateCnt As Variant
Dim EndDays As Integer
BegDate = DateValue(BegDate)
EndDate = DateValue(EndDate)
WholeWeeks = DateDiff("w", BegDate, EndDate)
DateCnt = DateAdd("ww", WholeWeeks, BegDate)
EndDays = 0
Do While DateCnt < EndDate
If Format(DateCnt, "ddd") <> "Sun" And _
Format(DateCnt, "ddd") <> "Sat" Then
EndDays = EndDays + 1
End If
DateCnt = DateAdd("d", 1, DateCnt)
Loop
Work_Days = WholeWeeks * 5 + EndDays
End Function