Please post code between CODE tags to retain indentation and readability.
You have WriteLog function but it is not called from any of the posted code. Why did you post it if it is not used?
Try adding error handler code to the procedure and put the INSERT sql within the error handler. Review https://www.accessforums.net/showthread.php?t=66664