Question

iif((([START DATE]<(cdate(format(year() & [WinterStartMonth] & [WinterStartDay],"####/##/##")))) AND ([START DATE]>(cdate(format(year() & [SummerStartMonth] & [SummerStartDay], "####/##/##"))))), (DateAdd("d", [WinterInspectionDropDead], [START DATE])), (DateAdd("d", [SummerInspectionDropDead], [START DATE]))) AS dropDead

Can anybody spot the issue? I think I've gone OTT with the brackets but I can't seem to shake the error.

Was it helpful?

Solution

You can usually use VBA to easily spot the errors, so:

IIf([START DATE] < DateSerial(Year(Date),[WinterStartMonth],[WinterStartDay]) _
And [START DATE] > DateSerial(Year(Date),[SummerStartMonth],[SummerStartDay]), _
DateAdd("d", [WinterInspectionDropDead], [START DATE]), DateAdd("d", _
[SummerInspectionDropDead], [START DATE]))

Just remove the line break characters for SQL:

IIf([START DATE] < DateSerial(Year(Date), [WinterStartMonth], [WinterStartDay]) 
  And [START DATE] > DateSerial(Year(Date),[SummerStartMonth], [SummerStartDay]),
  DateAdd("d", [WinterInspectionDropDead], [START DATE]),
  DateAdd("d", [SummerInspectionDropDead], [START DATE])) As Result

Or probably better:

IIf([START DATE] < DateSerial(Year(Date), [WinterStartMonth], [WinterStartDay]) 
  And [START DATE] > DateSerial(Year(Date),[SummerStartMonth],[SummerStartDay]),
 [START DATE] + [WinterInspectionDropDead], 
 [START DATE] + [SummerInspectionDropDead]) 
As Result
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top