Thanks for taking the time to explain that and for doing it so well.
My future coding should be much improved because I can now consider such issues as this and how to test for errors. At the moment it's all a mish mash of other people's code, cut and pasted. It will be good to be able to write these things from scratch myself.
I have copied your post into my 'reference' notes. So I shouldn't ever need to ask the question again.