Hi,
I created a formula that identifies holidays not using hardcoded dates in my detail lines. It works fine for dates this year, but when a date parameter from last year is entered, I get the out of range error message. I'm not sure what I haven't accounted for. All data, including dates, are pulled directly from a table.
Sorry if I put more than needed here. I didn't know what would be helpful. Thanks for any help you can give.
I created a formula that identifies holidays not using hardcoded dates in my detail lines. It works fine for dates this year, but when a date parameter from last year is entered, I get the out of range error message. I'm not sure what I haven't accounted for. All data, including dates, are pulled directly from a table.
Code:
Dim d1,LastDayOfMonth,ThirdMonday,FirstDayOfMonth,FirstMonday,LastMonday,SecondMonday, FourthThursday
d1 = cdate({tblOpsReportFinal.Date})
LastDayOfMonth = DateSerial(Year(d1), Month(d1) + 1, 1 - 1)
FirstDayOfMonth = DateSerial(Year(d1), Month(d1), 1)
ThirdMonday = FirstDayOfMonth + (3 * 7 - (WeekDay(FirstDayOfMonth, crMonday) - 1))
FirstMonday = FirstDayOfMonth + (1 * 7 - (WeekDay(FirstDayOfMonth, crMonday) - 1))
SecondMonday = FirstDayOfMonth + (2 * 7 - (WeekDay(FirstDayOfMonth, crMonday) - 1))
FourthThursday = FirstDayOfMonth + (4 * 7 - (WeekDay(FirstDayOfMonth, crThursday) - 1))
if (DatePart("m",d1) = 1 and datepart("dd",d1) = 01) or (DatePart("m",d1) = 1 and d1 = ThirdMonday) or (DatePart("m",d1) = 2 and d1 = ThirdMonday) or _
(DatePart("m",d1) = 5 and d1 = ThirdMonday) or (DatePart("m",d1) = 7 and datepart("dd",d1) = 04) or _
(DatePart("m",d1) = 9 and d1 = FirstMonday) or (DatePart("m",d1) = 10 and d1 = SecondMonday) or _
(DatePart("m",d1) = 11 and datepart("dd",d1) = 11) or (DatePart("m",d1) = 11 and d1 = FourthThursday) or _
(DatePart("m",d1) = 12 and datepart("dd",d1) = 25) and (weekday(d1,crsaturday)<>1 or weekday(d1,crsunday)<>1) then
formula = cryellow
elseif (weekday(d1,crsaturday)=1 or weekday(d1,crsunday)=1) then
formula=crsilver
else
formula=crwhite
end if
Sorry if I put more than needed here. I didn't know what would be helpful. Thanks for any help you can give.