Number of Workdays

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

It looks as though your function is incorrect. You're already passing 2
dates BegDate and EndDate to the function. The lines

BegDate = DaveValue(Date1)
EndDate = DateValue(Date2)

aren't required.

If you're trying to compare the ApplicationDate in your table to today's
date, you could have a query with a calculated field:

WorkingDays: Work_Days([ApplicationDate], Date())
 
Hello,

I am attempting to calculate the number of business days
between two dates. I have the following VB code. My
problem is, I don't know how to reference the my fields in
my table. For example, if my field is called
ApplicationDate in the Loans table, what would be the
syntax to put it in place of the Date1?

Thanks!

______________

Option Compare Database

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 = DaveValue(Date1)
EndDate = DateValue(Date2)
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
 
Back
Top