I've solved this myself. Seems that it was just one record that was causing the error so I deleted the record and created a new duplicate. The code works as originally written. Thank all.