Thanks for all the posts on this error.
The error doesn't actually stop the program from working. The user just presses Continue and the program carries on working.
The posts have given me lots of leads on how to fix the problem/make my code more elegant. However, I will probably leave it broken for now.