We help IT Professionals succeed at work.
Get Started

Use a table for Holidays in function rather than an array

Last Modified: 2012-05-12
I in no way created the attached code.  It works - however, rather than using an arry in the code, I am trying to figure out how to use data from the tblHoliday table.  That is, I need to have in the code a lookup of hoidays between the varStartDate and varEndDate to use in place of the aryHolidayList.  This is in an ACCESS 2003 database in VBA where the user will type in the varStartDate and varEndDate from a form.
Public Function fntWorkDays(varStartDate As Variant, varEndDate As Variant) As Long
'Returns the number of actual workdays between two dates and also accounts for holidays
Dim lngCounter      As Long
Dim lngDayCount     As Long
Dim aryHolidaysList()
Dim aryMember
Dim blnFound        As Boolean

blnFound = False

varStartDate = DateValue(varStartDate)
varEndDate = DateValue(varEndDate)

aryHolidaysList = Array("1/1/2012", "1/16/2012", "2/20/2012", "5/28/2012", "7/4/2012", "9/3/20121", "10/8/2012", _
"11/12/2012", "11/22/2012", "12/25/2012")

For lngCounter = varStartDate To varEndDate
    If Weekday(lngCounter, vbMonday) < 6 Then
        For Each aryMember In aryHolidaysList
            If Format(aryMember, "mm/dd/yyyy") = Format(lngCounter, "mm/dd/yyyy") Then
                blnFound = True
                Exit For
                blnFound = False
            End If
        Next aryMember

        If blnFound = False Then
            lngDayCount = lngDayCount + 1
        End If
    End If
Next lngCounter
    fntWorkDays = lngDayCount
End Function

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2013
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE