SteveM...
Your code is painfully hard to eyeball (aka troubleshoot) because of poor formatting. [Frown]
KiXstrip.exe is a great tool that will painlessly indent your scripts for readability, and error check your code. [Smile]
For a win-win solution check this out --> How do we check and format code for scripts? [Cool]
_________________________
We all live in a Yellow Subroutine...