Number of Workdays

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())
 
H

Harmony

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top