Nested IIF statement fail
Posted: Wed Dec 28, 2022 10:33 pm
The syntax checker says that this is OK. But when I preview the report I get 33 compilation errors. Not sure what I am doing wrong.
{IIF(Month(Today) = 1, (DateSerial(Year(Today) - 2, 12, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 2, (DateSerial(Year(Today) - 1, 1, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 3, (DateSerial(Year(Today) - 1, 2, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 4, (DateSerial(Year(Today) - 1, 3, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 5, (DateSerial(Year(Today) - 1, 4, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 6, (DateSerial(Year(Today) - 1, 5, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 7, (DateSerial(Year(Today) - 1, 6, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 8, (DateSerial(Year(Today) - 1, 7, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 9, (DateSerial(Year(Today) - 1, 8, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 10, (DateSerial(Year(Today) - 1, 9, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 11, (DateSerial(Year(Today) - 1, 10, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 12, (DateSerial(Year(Today) - 1, 11, 1)).ToString("MM.dd.yyyy"),""))))))))))))}
The error of compilation
The error of compilation is found in the 'Text' property of the 'Text_14' component:
'Month' is not declared. It may be inaccessible due to its protection level.
{IIF(Month(Today) = 1, (DateSerial(Year(Today) - 2, 12, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 2, (DateSerial(Year(Today) - 1, 1, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 3, (DateSerial(Year(Today) - 1, 2, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 4, (DateSerial(Year(Today) - 1, 3, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 5, (DateSerial(Year(Today) - 1, 4, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 6, (DateSerial(Year(Today) - 1, 5, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 7, (DateSerial(Year(Today) - 1, 6, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 8, (DateSerial(Year(Today) - 1, 7, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 9, (DateSerial(Year(Today) - 1, 8, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 10, (DateSerial(Year(Today) - 1, 9, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 11, (DateSerial(Year(Today) - 1, 10, 1)).ToString("MM.dd.yyyy"),
IIF(Month(Today) = 12, (DateSerial(Year(Today) - 1, 11, 1)).ToString("MM.dd.yyyy"),""))))))))))))}
The error of compilation
The error of compilation is found in the 'Text' property of the 'Text_14' component:
'Month' is not declared. It may be inaccessible due to its protection level.