J
Jen
I found the following code for determing Previous Business Day on this site.
When I test is using "12/29/09" as the BgnDate, it returns "12/29/09" when it
should be returning "12/28/09".
Any thoughts?
Public Function PreviousBD(BgnDate As Date) As Date
Dim rsHolidays As DAO.Recordset
Dim bdNum As Integer
Dim isHoliday As Boolean
Dim strSQL As String
strSQL = "Select Holiday from tblBCBSMN_Holidays"
Set rsHolidays = CurrentDb.OpenRecordset(strSQL)
Do
bdNum = Weekday(BgnDate)
'determine which day the date is,
'then calc previous BD
Select Case bdNum
'Tuesday to Saturday
Case 3 - 7
BgnDate = BgnDate - 1
'Sunday
Case 1
BgnDate = BgnDate - 2
'Monday
Case 2
BgnDate = BgnDate - 3
End Select
' now check if BgnDate is a holiday
'search the recordset
rsHolidays.FindFirst "[Holiday] = #" & BgnDate & "#"
If rsHolidays.NoMatch Then
Exit Do
Else
BgnDate = BgnDate - 1
'check once more for back to back holidays
rsHolidays.FindFirst "[Holiday] = #" & BgnDate & "#"
If rsHolidays.NoMatch Then 'True = no records
Exit Do
Else
BgnDate = BgnDate - 1
End If
End If
Loop
'clean up
rsHolidays.Close
Set rsHolidays = Nothing
'return Previous Business Day
PreviousBD = BgnDate
End Function
Thanks!
When I test is using "12/29/09" as the BgnDate, it returns "12/29/09" when it
should be returning "12/28/09".
Any thoughts?
Public Function PreviousBD(BgnDate As Date) As Date
Dim rsHolidays As DAO.Recordset
Dim bdNum As Integer
Dim isHoliday As Boolean
Dim strSQL As String
strSQL = "Select Holiday from tblBCBSMN_Holidays"
Set rsHolidays = CurrentDb.OpenRecordset(strSQL)
Do
bdNum = Weekday(BgnDate)
'determine which day the date is,
'then calc previous BD
Select Case bdNum
'Tuesday to Saturday
Case 3 - 7
BgnDate = BgnDate - 1
'Sunday
Case 1
BgnDate = BgnDate - 2
'Monday
Case 2
BgnDate = BgnDate - 3
End Select
' now check if BgnDate is a holiday
'search the recordset
rsHolidays.FindFirst "[Holiday] = #" & BgnDate & "#"
If rsHolidays.NoMatch Then
Exit Do
Else
BgnDate = BgnDate - 1
'check once more for back to back holidays
rsHolidays.FindFirst "[Holiday] = #" & BgnDate & "#"
If rsHolidays.NoMatch Then 'True = no records
Exit Do
Else
BgnDate = BgnDate - 1
End If
End If
Loop
'clean up
rsHolidays.Close
Set rsHolidays = Nothing
'return Previous Business Day
PreviousBD = BgnDate
End Function
Thanks!