Thanks for the pointers guys, Yes I see how the End statement would work in that example I posted but I think it would be a bit dangerous in my actual system, as Tony said. I'm going to try declaring everything locally rather than module level and passing as and when they are needed.