First, here is a function that counts the number of working days between two
dates. You will want to have a Holidays table to enter non working weekdays
in. For this function, it is called tblHolidays. It has two fields HolDate
(The Date of the Holiday) and HolDescription (Plain Text to show what holiday
it is.) The description isn't used in this function.
Function CalcWorkDays(dtmStart As Date, dtmEnd As Date) As Integer
On Error GoTo CalcWorkDays_Error
'Calculates the number of days between the dates
'Add one so all days are included
CalcWorkDays = DateDiff("d", dtmStart, dtmEnd) - _
(DateDiff("ww", dtmStart, dtmEnd, 7) + _
DateDiff("ww", dtmStart, dtmEnd, 1)) + 1
'Subtract the Holidays
CalcWorkDays = CalcWorkDays - DCount("*", "holidays", "[holdate] between
#" _
& dtmStart & "# And #" & dtmEnd & "#")
CalcWorkDays_Exit:
On Error Resume Next
Exit Function
CalcWorkDays_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure CalcWorkDays of Module modDateFunctions"
GoTo CalcWorkDays_Exit
End Function
Now, here is a function using the same table that determines if any given
date is a work day:
Public Function IsWorkDay(dtmSomeDay As Date) As Boolean
Dim blnWorkingDay
blnWorkingDay = Weekday(dtmSomeDay, vbMonday) < 6
If blnWorkingDay Then
blnWorkingDay = IsNull(DLookup("[Holdate]", "Holidays", _
"[Holdate] = #" & dtmSomeDay & "#"))
End If
IsWorkDay = blnWorkingDay
End Function
So, using a variation of mscertified's suggestion on finding the first day
of the next month:
dtmFirstOfMonth = DateSerial(Year(Date),Month(Date)+1,1)
And the other functions above, you should be able to get what you want. Now
if you need to know the first working day of the next month, this function
will do it:
Public Function NextWorkDay(dtmSomeDay As Date)
Dim dtmDayOff As Date
dtmSomeDay = DateAdd("d", 1, dtmSomeDay)
Do Until IsWorkDay(dtmSomeDay)
dtmSomeDay = DateAdd("d", 1, dtmSomeDay)
Loop
NextWorkDay = dtmSomeDay
End Function
--
Dave Hargis, Microsoft Access MVP
Juli Intern said:
Hi,
I was struggling to create an expression that would show the last working
day of the next month. Or do any date calculation using only working days. I
don't now if it exist and would appreciate if someone could help me.