Without looking at your code and as the error code indicates, you are missing an End IF. make sure that for every IF statement that includes more that one instruction you have an End IF.
eg:
'here you need End IF
If a = b then
instruction 1
intruction 2
end if
'this is fine too. you don't need end if here.
if a= b then instruction
Hope this helps. As Pat said, a sample of your code would help diagnose the problem.