dcollard23
Registered User.
- Local time
- Today, 08:13
- Joined
- Jun 15, 2009
- Messages
- 87
Is there a way to edit this module to where my start date may be on a weekend or holiday and if it is then the calculation between my two dates will start calculating on the following business day but when doing my calculation to obtain the end date holidays and weekends are taken out and the end date will fall on a business day?
Example: Startdate is 3/10/2012 (the transaction I am doing has to be completed in 1 day from the start date) so I am getting an end date of 3/12/2012 It looks as if the current module above is taking me back to a start date of 3/9/2012 then doing the calculation (taking out 3/10 and 3/11) giving me 3/12/2012 instead of giving me 3/13/2012 ( the entry date may be 3/10/2012 but the caculation should start on 3/12/12 giving me the end date of 3/13/2012). The start date can be a holiday also.
Public Function fAddBusinessDay(pStart As Date, pAdd As Integer)
'Adds the proper Business day skipping holidays and weekends
'adapted from code by Arvin Meyer 05/26/98
On Error GoTo Err_fAddBusinessDay
Do While pAdd > 0
pStart = pStart + 1
If Weekday(pStart) <> 1 And Weekday(pStart) <> 7 Then
'not Sunday nor Saturday
If DCount("*", "tblHolidays", "[holidaydate]=#" & pStart & "#") = 0 Then
'not holiday
pAdd = pAdd - 1
End If
End If
Loop
fAddBusinessDay = pStart
Exit_fAddBusinessDay:
Exit Function
Err_fAddBusinessDay:
MsgBox Err.Description
Resume Exit_fAddBusinessDay
End Function
Thanks for your assistance in advance.
I hope I wasn't too confusing.
I am looking for a solution. If possible please tell me what to do and how to do it.
Elaine
Example: Startdate is 3/10/2012 (the transaction I am doing has to be completed in 1 day from the start date) so I am getting an end date of 3/12/2012 It looks as if the current module above is taking me back to a start date of 3/9/2012 then doing the calculation (taking out 3/10 and 3/11) giving me 3/12/2012 instead of giving me 3/13/2012 ( the entry date may be 3/10/2012 but the caculation should start on 3/12/12 giving me the end date of 3/13/2012). The start date can be a holiday also.
Public Function fAddBusinessDay(pStart As Date, pAdd As Integer)
'Adds the proper Business day skipping holidays and weekends
'adapted from code by Arvin Meyer 05/26/98
On Error GoTo Err_fAddBusinessDay
Do While pAdd > 0
pStart = pStart + 1
If Weekday(pStart) <> 1 And Weekday(pStart) <> 7 Then
'not Sunday nor Saturday
If DCount("*", "tblHolidays", "[holidaydate]=#" & pStart & "#") = 0 Then
'not holiday
pAdd = pAdd - 1
End If
End If
Loop
fAddBusinessDay = pStart
Exit_fAddBusinessDay:
Exit Function
Err_fAddBusinessDay:
MsgBox Err.Description
Resume Exit_fAddBusinessDay
End Function
Thanks for your assistance in advance.
I hope I wasn't too confusing.
I am looking for a solution. If possible please tell me what to do and how to do it.
Elaine