Here is a function that does exactly that. Put it in a standard module and
you can call it from anywhere in your application. You will need a holiday
table with one record for each holiday. In this code the table name is
holidays and the field in holdate.
'---------------------------------------------------------------------------------------
' Procedure : CalcWorkDays
' DateTime : 5/8/2006 16:34
' Author : Dave Hargis
' Purpose : Counts the number of days between two dates excluding Saturdays,
' : Sundays, and any days in the Holidays table
'---------------------------------------------------------------------------------------
'
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
--
Dave Hargis, Microsoft Access MVP
J. LeRoy said:
I'm a New Access Developer learning to create a Tracking Data Application
with MS Access with VBA. I'm stock with my project because I can't see any
result in my coding. Would you please help to write a VBA code into Ms
Access 2003 to calculate difference days between days minus Saturday, Sunday,
And 10 days Holidays?
Best Regards,
Just