The post can be found here:
https://bytes.com/topic/access/answers/954598-calculate-date-but-do-not-count-weekends-holidays
Here is the algorithm by Adezii I am referring to:
[Code]..
1.Public Function fCalcWorkDays2( dteStartDate As Date, lngNumOfDays As Long)
2. Dim lngCount As Long
3. Dim lngCtr As Long
4. Dim dteDate As Date
5.
6. lngCount = 0
7. lngCtr = 1
8.
9. Debug.Print "Date", "Day Count", "Weekday"
10.
11. Do
12. dteDate = DateAdd("d", lngCtr, dteStartDate)
13. Select Case Weekday(dteDate )
14. Case 7, 1 'Saturday and Sunday, do nothing
15. Case Else 'Monday thru Friday, OK
16. 'Is it a Holiday as posted in tblHolidays?
17. If DCount("*", "tblHoliday s", "[Date] = #" & dteDate & "#") < 1 Then 'NOT Holiday
18. lngCount = lngCount + 1 'Increment Counter
19. Debug.Print dteDate, lngCount, Weekday(dteDate )
20. End If
21. End Select
22. lngCtr = lngCtr + 1
23. Loop While lngCount < lngNumOfDays
24. fCalcWorkDays2 = dteDate
25. End Function]
[Code/]..
I work for the Air Force and I am trying to create function that will do this very thing, but mine is adding too many days. Adezii's function looks much cleaner, but I do not understand a couple of items.
1. Would anyone be able to explain what is meant by line 17:
If DCount("*", "tblHoliday s", "[Date] = #" & dteDate & "#") < 1 ?
Does this mean his dates in tblHolidays are enclosed in pound signs, or is that the way it needs to be written in the function?
2. I don't quite understand how typing Case 7,1 on line 14 tells access to ignore Saturday and Sunday. Can someone explain that?
If you have questions or require additional information, please email me.
Thanks!
Mike Munitz
https://bytes.com/topic/access/answers/954598-calculate-date-but-do-not-count-weekends-holidays
Here is the algorithm by Adezii I am referring to:
[Code]..
1.Public Function fCalcWorkDays2( dteStartDate As Date, lngNumOfDays As Long)
2. Dim lngCount As Long
3. Dim lngCtr As Long
4. Dim dteDate As Date
5.
6. lngCount = 0
7. lngCtr = 1
8.
9. Debug.Print "Date", "Day Count", "Weekday"
10.
11. Do
12. dteDate = DateAdd("d", lngCtr, dteStartDate)
13. Select Case Weekday(dteDate )
14. Case 7, 1 'Saturday and Sunday, do nothing
15. Case Else 'Monday thru Friday, OK
16. 'Is it a Holiday as posted in tblHolidays?
17. If DCount("*", "tblHoliday s", "[Date] = #" & dteDate & "#") < 1 Then 'NOT Holiday
18. lngCount = lngCount + 1 'Increment Counter
19. Debug.Print dteDate, lngCount, Weekday(dteDate )
20. End If
21. End Select
22. lngCtr = lngCtr + 1
23. Loop While lngCount < lngNumOfDays
24. fCalcWorkDays2 = dteDate
25. End Function]
[Code/]..
I work for the Air Force and I am trying to create function that will do this very thing, but mine is adding too many days. Adezii's function looks much cleaner, but I do not understand a couple of items.
1. Would anyone be able to explain what is meant by line 17:
If DCount("*", "tblHoliday s", "[Date] = #" & dteDate & "#") < 1 ?
Does this mean his dates in tblHolidays are enclosed in pound signs, or is that the way it needs to be written in the function?
2. I don't quite understand how typing Case 7,1 on line 14 tells access to ignore Saturday and Sunday. Can someone explain that?
If you have questions or require additional information, please email me.
Thanks!
Mike Munitz
Comment