Networkdays in Access?

M

milaide

Is there a way for Access to recogonize holidays in DateDiff function? I am
using the DateDiffW function right now, to pull just workdays, but want it to
be able to recognize holidays as well. These results will be pulled in a
measurable table, so I need to make this as easy as possible.

Thanks!
 
K

Klatuu

There is no way for Access to recognize holidays. Different countries, even
different entities within a country have different holidays. For example, I
doubt if anyone in North Dakota even knows there is a San Jancinto holiday
(Texas Independace Day). So, you will need a table that defines your
holidays. Here is a funtion that returns the number of working days between
two dates. It excludes saturdays, sundays, and defined holidays. It uses a
table named (cleverly) holidays with a date field named holdate.

Function CalcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer
'Calculates the number of working days between two dates
'dtmStart - the first day to include in the range
'dtmEnd - the last day to include in the range
'Returns the number of working days between the two dates
'Both dates are counted if they are working days

Dim intTotalDays As Integer ' Counter for number of days
Dim dtmToday As Date ' To increment the date to compare

intTotalDays = DateDiff("d", dtmStart, dtmEnd) + 1 'Start with total days
'Add one to include
First Day
dtmToday = dtmStart 'Initiate compare date
Do Until dtmToday > dtmEnd
If Weekday(dtmToday, vbMonday) > 5 Then 'It is Saturday or
Sunday
intTotalDays = intTotalDays - 1 'Take one day away
for Weekend day
ElseIf Not IsNull(DLookup("[Holdate]", "Holidays", _
"[Holdate] = #" & dtmToday & "#")) Then 'It is a holiday
intTotalDays = intTotalDays - 1 'Take one day away
for the Holiday
End If
dtmToday = DateAdd("d", 1, dtmToday) 'Add a day for next
compare
Loop 'Until dtmToday > dtmEnd All days have been
compared
CalcWorkDays = intTotalDays 'Return the value
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