Function AddWkDaysH(vardate As Variant, numdays As Integer, _
pexclude As String, holidates As String)
'*******************************************
'Name: AddWkDays (Function)
'Purpose: Simple, non-formula method of
' adding weekdays to a given
' date
'Inputs: ? ? AddWkdaysH("08/25/02", 10, "17", "37501")
'Output: 9/9/02
'Note: pexclude = the weekdays to exclude
' (e.g., Sat = 7, Sunday = 1)
' the holiday string uses the date as stored by
' Access, e.g. US Labor Day, first Monday in September,
' is 9/2/02. Access stores this as cDbl(#9/2/02) = 37501
'*******************************************
Dim thedate As Date, n As Integer, incl As Boolean
thedate = DateValue(vardate)
incl = False
Do While InStr(pexclude, WeekDay((thedate) + 1)) > 0 Or InStr(holidates, CLng((thedate) + 1)) > 0
thedate = thedate + 1
incl = True
Loop
thedate = thedate + IIf(incl = False, 1, 0)
n = 0
Do While n < numdays
If InStr(pexclude, WeekDay(thedate)) = 0 And InStr(holidates, CLng(thedate)) = 0 Then
n = n + 1
End If
If n = numdays Then Exit Do
thedate = thedate + 1
Loop
AddWkDaysH = thedate
End Function
[code]
How you develop your table of holidates is a whole separate topic. If, however, you have an
accurate table of holidates, a calculated field in a query, using a variation of [b] AcDate: CDbl([theDate])[/b] will return the date as stored by Access. The reason for using this, rather
than short-date, is space and ease of coding.
Couple of other considerations:
(1) You'll probably wanted a 'Selected' (check-box) field to allow the user to tailor the holidays to be considered (e.g., St. Patrick's Day in most locales is a business day).
(2) What happens when your calculation spans one or more years? You cannot just take the month/day of the previous year and add the new year (e.g., the previous input used what is represented as a calendar for 2002, but it in fact appears to be for 2000. Only the dates that fall on a specific calendar date (Christmas, New Years, etc.) are correct.