P
Patrick
I have a module setup that calculates the number of
working days between two dates. I got the code in the
knowledge base. I know how to call the function in my
query and it works if my fields are named BegDate and
EndDate. Work_Days([BegDate], [EndDate]) But in the table
the fields I want to use are Date Initiated and Date
Observed. How do I pass these dates over? What in the
code would I need to change to accept these two dates?
Here is the code:
Function Work_Days(BegDate As Variant, EndDate As Variant)
As Integer
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
Any info would be great. Thanks
working days between two dates. I got the code in the
knowledge base. I know how to call the function in my
query and it works if my fields are named BegDate and
EndDate. Work_Days([BegDate], [EndDate]) But in the table
the fields I want to use are Date Initiated and Date
Observed. How do I pass these dates over? What in the
code would I need to change to accept these two dates?
Here is the code:
Function Work_Days(BegDate As Variant, EndDate As Variant)
As Integer
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
Any info would be great. Thanks