Ok,
I changed the second piece of code to all be Object Oriented but no luck. For now I've just done a work around that is more at my level of understanding. (No cookies.)
Fair comment about reading the docs too. I've just been skimming them up until now. I've printed them out today - some light bedtime reading.
Thanks for your input.