Hi
Trying to write a function to return only biz days from a given date (M-F). I want 4 biz days ago (backwards) from a given date, usually Today's date. I need it to work longer than a period of one week because I need the code to check 4th biz day for the past month or so (backwards). Today is Tuesday, I need it to check 4 biz days ago - so check Wednesday the 4th, also check 8 days ago - Thurs the 29th of July... etc.
I've began writing some code to return a Date function based on a passed in date and a number specified, but I'm having trouble wracking my brain to figure out what to do when I send it something above 5 days, like lstBizDate(Date, 8) ... I can't quite remember from my old college coding classes how to realize that there were 2 weekends between now and then ... DateDiff()? .. and realize what day to return.
I've taken some code from this thread: How can i calculate business days? thread181-47925. It has some serious processing errors. It's decent, but I absolutely cannot have this processing holidays, so I have removed the holiday check from the code. It appears to work in some cases, however... a lot of the time it is not functional and it gives me a few days off. I am having trouble following the code, which is relatively rare for me, but I've been looking at it for so long that I could really use an outside perspective.
Please look to the thread mentioned for Michael's code... try to fix it. It really has problems. Just get rid of the recordset and query defs in his code, and everything to do with the Holidays table. Post it into your own DB and test away.
Here's what I'v written sofar if anyone wants to just simplify it and help me finish it up. I could use a push in the right direction. It's incomplete, I've just started writing it, but I can't even think of the algorithm I need to use..
Public Function lstBizDay(dt As Date, pstDys As Integer) As Date
'Written 10/10/04
'Designed to check the value of a passed in date and subtract
'the passed in business days.
Dim tmpDate As Date
tmpDate = dt - pstDys
If Weekday(tmpDate) = 7 Or Weekday(tmpDate) = 1 Then 'day is Sat or Sun
MsgBox (Weekday(tmpDate))
tmpDate = tmpDate - 2
lstBizDay = tmpDate
Exit Function
End If
lstBizDay = tmpDate
End Function
------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------
Trying to write a function to return only biz days from a given date (M-F). I want 4 biz days ago (backwards) from a given date, usually Today's date. I need it to work longer than a period of one week because I need the code to check 4th biz day for the past month or so (backwards). Today is Tuesday, I need it to check 4 biz days ago - so check Wednesday the 4th, also check 8 days ago - Thurs the 29th of July... etc.
I've began writing some code to return a Date function based on a passed in date and a number specified, but I'm having trouble wracking my brain to figure out what to do when I send it something above 5 days, like lstBizDate(Date, 8) ... I can't quite remember from my old college coding classes how to realize that there were 2 weekends between now and then ... DateDiff()? .. and realize what day to return.
I've taken some code from this thread: How can i calculate business days? thread181-47925. It has some serious processing errors. It's decent, but I absolutely cannot have this processing holidays, so I have removed the holiday check from the code. It appears to work in some cases, however... a lot of the time it is not functional and it gives me a few days off. I am having trouble following the code, which is relatively rare for me, but I've been looking at it for so long that I could really use an outside perspective.
Please look to the thread mentioned for Michael's code... try to fix it. It really has problems. Just get rid of the recordset and query defs in his code, and everything to do with the Holidays table. Post it into your own DB and test away.
Here's what I'v written sofar if anyone wants to just simplify it and help me finish it up. I could use a push in the right direction. It's incomplete, I've just started writing it, but I can't even think of the algorithm I need to use..
Public Function lstBizDay(dt As Date, pstDys As Integer) As Date
'Written 10/10/04
'Designed to check the value of a passed in date and subtract
'the passed in business days.
Dim tmpDate As Date
tmpDate = dt - pstDys
If Weekday(tmpDate) = 7 Or Weekday(tmpDate) = 1 Then 'day is Sat or Sun
MsgBox (Weekday(tmpDate))
tmpDate = tmpDate - 2
lstBizDay = tmpDate
Exit Function
End If
lstBizDay = tmpDate
End Function
------------------
-JPeters
Got a helpful tip for Access Users? Check out and contribute to 'How to Keep Your Databases from becoming Overwhelming!'
thread181-293590
jpeters@guidemail.com
------------------