S
sojo
Below is a Function to calculate the number of workdays between to dates.
The code came from: http://www.mvps.org/access/, so the author gets full
credit. There is so much great info available on sites like these!
My question. How do I have the result displayed on a form? In otherwords, I
want to have three fields on the form. One showing the startdate, the
second enddate, and the third, an unbound field which would show the result
based on the code below. Hope this question makes sense. I recently began
using Access 2000 at work and have been on a huge learning curve ever
since. I understand (more or less) how the code works, but can't figure out
how to associate it with the three fields mentioned above.
Thanks.
'*********** Code Start **************
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
'*********** Code End **************
The code came from: http://www.mvps.org/access/, so the author gets full
credit. There is so much great info available on sites like these!
My question. How do I have the result displayed on a form? In otherwords, I
want to have three fields on the form. One showing the startdate, the
second enddate, and the third, an unbound field which would show the result
based on the code below. Hope this question makes sense. I recently began
using Access 2000 at work and have been on a huge learning curve ever
since. I understand (more or less) how the code works, but can't figure out
how to associate it with the three fields mentioned above.
Thanks.
'*********** Code Start **************
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
'*********** Code End **************