R
Richard
Hi
I need to create a function that gets 3 working days before a workshop date.
I created the following code but doesn't seem get what I need.
If today is Tuesday (18/07/2006), and I type getReturnDate(Date(),1), I get
17/07/2006. Correct.
But when I type getReturnDate(Date(),2), I get 16/07/06 which is a Sunday.
Please check and many thanks in advance.
Richard
Public Function getReturnDate(WORKSHOPDATE As Date, intWorkingDays As
Integer) As Date
On Error GoTo ErrHandler
Dim i As Integer
Dim dte As Date
i = 0
dte = WORKSHOPDATE
Do Until i = intWorkingDays
Select Case Weekday(dte)
Case Is = 1, 7
dte = dte - 1
Case Is = 2, 3, 4, 5, 6
dte = dte - 1
i = i + 1
End Select
Loop
getReturnDate = dte
ExitHere:
Exit Function
ErrHandler:
MsgBox Err.Description, , Err.Number
Resume ExitHere
End Function
I need to create a function that gets 3 working days before a workshop date.
I created the following code but doesn't seem get what I need.
If today is Tuesday (18/07/2006), and I type getReturnDate(Date(),1), I get
17/07/2006. Correct.
But when I type getReturnDate(Date(),2), I get 16/07/06 which is a Sunday.
Please check and many thanks in advance.
Richard
Public Function getReturnDate(WORKSHOPDATE As Date, intWorkingDays As
Integer) As Date
On Error GoTo ErrHandler
Dim i As Integer
Dim dte As Date
i = 0
dte = WORKSHOPDATE
Do Until i = intWorkingDays
Select Case Weekday(dte)
Case Is = 1, 7
dte = dte - 1
Case Is = 2, 3, 4, 5, 6
dte = dte - 1
i = i + 1
End Select
Loop
getReturnDate = dte
ExitHere:
Exit Function
ErrHandler:
MsgBox Err.Description, , Err.Number
Resume ExitHere
End Function