Your first IF is fully contained within one line, so there is no Else ... Endif to associate with it. Therefore that ElseIf lower down is not connected to an If (and has no EndIf) anyway.