Thanks for your help. I found a very simple bit of code that closes the layer.

Cheers