The extra EndIf directly after the Loop might be breaking things. If I counted correctly it is not needed anymore. Every If can optionally have one Else but absolutely needs one Endif. Also you use While Not @ERROR = 0. It would be better to use While Not @ERROR or While @ERROR = 0 or While @ERROR <> 0 depending on when you want the code to be executed or not.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.