Many thanks khodr.
The way you indicated was roughly the the method I was using. I have looked at this several time over Christmas and the New Year and still I have no idea why it stopped working.
In the end I scrapped the routine and started again. It now works O.K.
As an old school friend of mine used to say " Oh the perversity of Inanimate objects!"