J
Joker via AccessMonster.com
Hello,
I have an odd request from work which is giving me quite a bit of trouble. I
need to figure out the 3rd Business day prior to the 18 in VBA. I have been
trying to manipulate the code "GetBusinessDay" by Arvin Meyer to no success
(below). Just a FYI.. This is going to be used in a user defined function.
Any help/thoughts will be GREATLY appreciated. Thanks.
Function GetBusinessDay(datStart As Date, intDayAdd As Variant)
On Error GoTo Error_Handler
'Adds/Subtracts the proper Business day skipping holidays and weekends
'Requires a table (tblHolidays) with a date field (HolidayDate)
'Arvin Meyer 05/26/98 revised 3/12/2002
'© Arvin Meyer 1998 - 2002 You may use this code in your application provided
author
' is given credit. This code may not be distributed as part of a collection
' without prior written permission. This header must remain intact.
Dim rst As DAO.Recordset
Dim DB As DAO.Database
'Dim strSQL As String
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
If intDayAdd > 0 Then
Do While intDayAdd > 0
datStart = datStart + 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday
Then
If rst.NoMatch Then intDayAdd = intDayAdd - 1
End If
Loop
ElseIf intDayAdd < 0 Then
Do While intDayAdd < 0
datStart = datStart - 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday
Then
If rst.NoMatch Then intDayAdd = intDayAdd + 1
End If
Loop
End If
GetBusinessDay = datStart
Exit_Here:
rst.Close
Set rst = Nothing
Set DB = Nothing
Exit Function
Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here
End Function
I have an odd request from work which is giving me quite a bit of trouble. I
need to figure out the 3rd Business day prior to the 18 in VBA. I have been
trying to manipulate the code "GetBusinessDay" by Arvin Meyer to no success
(below). Just a FYI.. This is going to be used in a user defined function.
Any help/thoughts will be GREATLY appreciated. Thanks.
Function GetBusinessDay(datStart As Date, intDayAdd As Variant)
On Error GoTo Error_Handler
'Adds/Subtracts the proper Business day skipping holidays and weekends
'Requires a table (tblHolidays) with a date field (HolidayDate)
'Arvin Meyer 05/26/98 revised 3/12/2002
'© Arvin Meyer 1998 - 2002 You may use this code in your application provided
author
' is given credit. This code may not be distributed as part of a collection
' without prior written permission. This header must remain intact.
Dim rst As DAO.Recordset
Dim DB As DAO.Database
'Dim strSQL As String
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays",
dbOpenSnapshot)
If intDayAdd > 0 Then
Do While intDayAdd > 0
datStart = datStart + 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday
Then
If rst.NoMatch Then intDayAdd = intDayAdd - 1
End If
Loop
ElseIf intDayAdd < 0 Then
Do While intDayAdd < 0
datStart = datStart - 1
rst.FindFirst "[HolidayDate] = #" & datStart & "#"
If Weekday(datStart) <> vbSunday And Weekday(datStart) <> vbSaturday
Then
If rst.NoMatch Then intDayAdd = intDayAdd + 1
End If
Loop
End If
GetBusinessDay = datStart
Exit_Here:
rst.Close
Set rst = Nothing
Set DB = Nothing
Exit Function
Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here
End Function