I don't see where you pass @Error back to the calling script. You need to catch the errorlevel in the UDF and pass it back withthe EXIT parm.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.