VBA Function that ignores dates in a Holiday Table

S

Sorbit

I am currently using the code below in an Access Module to query data
for the previous day and not have to change to Date()-3 each Monday and
then back to Date()-1 after running all my Monday reports. It works
great, both with a Holidays table or without it. The code also works as
an Excel VBA function to call a date that does not include Saturdays
and Sundays. However, I cannot make it call the holiday table in
Access. Is there a way to do this? Or would it be simpler to somehow
name a table in Excel (on a separate spreadsheet) and somehow call that
range to make the function ignore an additional day; if the previous
day turns out to be a holiday? Anybody know?

Public Function AdjWorkDays(dteStart As Date, _
intNumDays As Long, _
Optional blnAdd As Boolean = True) As Date
AdjWorkDays = dteStart
Do While intNumDays > 0
If blnAdd Then
'-- Adding WorkDays
AdjWorkDays = AdjWorkDays + 1
Else
'-- Subtracting WorkDays
AdjWorkDays = AdjWorkDays - 1
End If
If Weekday(AdjWorkDays, vbMonday) <= 5 Then
'-- Use the following code if you have a "Holiday" table
' If Weekday(dteCurrDate, vbMonday) <= 5 And
IsNull(DLookup("[Holiday]", "tblHolidays", "[HolDate] = #" &
dteCurrDate & "#")) Then
intNumDays = intNumDays - 1
End If
Loop
End Function
 

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