Calculate a future date excluding weekends and holidays

M

MJS 2007

I have a form with a bound box of Date Rcvd, I would like to calculate a date
7 workdays later excluding weekends and holidays. For now I am using this
expression to roughly calculate a date. " =DateAdd("d",10,[Date_Rcvd]) " I
would like a more exact expression. Any suggestions?
 
A

Al Campagna

MJS,
A simple solution is to create a loop that starts with RcvdDate +7 days,
and adding one day per loop (LoopDate) until the
WeekDay(LoopDate) = 2 or 3 or 4 or 5 or 6.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
K

Klatuu

Here is a function that does exactly that. Notice the use of a calendar
table to also eliminate holidays.

'---------------------------------------------------------------------------------------
' Procedure : AddWorkDays
' DateTime : 5/8/2006 14:24
' Author : Dave Hargis
' Purpose : Determines the date of a work day (mon-fri) a number of days
after or
' : before a given date.
' Arguments : OriginalDate The date you want to add or subtract from to
determine a
' : worday
' : DaysToAdd Either a positive or negative number of working
days
' : Saturdays and Sundays are not counted
' : Holidays can also be omitted using a holiday table. The table
should
' : Contain one row for each holiday. As written, the table is
named
' : tblHolidays and the field used is a Date field named Holidate
' : No time vaule should be in the Holidate field. Time values
may produce
' : Incorrect Results
'---------------------------------------------------------------------------------------
'
Public Function AddWorkDays(OriginalDate As Date, DaysToAdd As Long) As Date
Dim lngAdd As Long
Dim lngDayCount As Long
Dim lngHolidayCount As Long

On Error GoTo AddWorkDays_Error

If DaysToAdd < 0 Then
lngAdd = -1
Else
lngAdd = 1
End If

AddWorkDays = OriginalDate

Do Until lngDayCount = DaysToAdd
AddWorkDays = DateAdd("d", lngAdd, AddWorkDays)
If Weekday(AddWorkDays, vbMonday) < 6 Then
If IsNull(DLookup("[holidate]", "tblHolidays", "[holidate] = #"
& _
AddWorkDays & "#")) Then
lngDayCount = lngDayCount + lngAdd
End If
End If
Loop

AddWorkDays_Exit:
On Error GoTo 0

Exit Function

AddWorkDays_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure AddWorkDays of Module modDateFunctions",
vbExclamation, conMsgTitle
GoTo AddWorkDays_Exit

End Function
 
A

Al Campagna

MJS,
Sorry about that... I forgot the Holiday portion of your question.
On my website (below) I have a 97 and 2003 sample file that calculates
workdays between two dates.
It uses the same loop I described for weekdays, but.... also checks a
"local calendar" table for holidays.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Al Campagna said:
MJS,
A simple solution is to create a loop that starts with RcvdDate +7
days,
and adding one day per loop (LoopDate) until the
WeekDay(LoopDate) = 2 or 3 or 4 or 5 or 6.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."






MJS 2007 said:
I have a form with a bound box of Date Rcvd, I would like to calculate a
date
7 workdays later excluding weekends and holidays. For now I am using this
expression to roughly calculate a date. " =DateAdd("d",10,[Date_Rcvd]) "
I
would like a more exact expression. Any suggestions?
 

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