Database and Website Design, Development, and Deployment--All in the Service of Your Mission
Here is some code that automatically builds procedures, along with copyright and error handling. This code was written to avoid typing exactly the same thing every time you create a new procedure. This is immensely helpful--because it's all standardized. We use a select structure in the error trapping portion of each procedure, as shown below. In this case, there are no errors expected, so there's only a "case else" case. If there were known errors that sometimes came up there would be more cases in the select structure.
In any case, here's a typical (though tiny) procedure from one of our databases, illustrating a call to the error trapping routine:
Here's the ErrorTrap routine in that database. This was written a few years ago and hasn't been modified since then. At some point we'll make this code fully generic, so the directories it uses are pulled from a table or a control on an always-open form.
It's pretty simple. First it saves the error information to a text file and then it puts up a message box to the user. If it fails to find the proper file on the server it writes to a file on the C:\ drive. If there's any other error in this routine, it tries again, and on the second error it just punts and tells the user to write everything down and go the database administrator.
Some people do a similar thing but write the error information to a table in their database. The reason we write the error log to a file instead is that if something serious goes wrong and you can't get into the back end of your database, you wouldn't be able to see the error table! You don't really need much functionality in this error log, and you can just link to the text file from any database, so there's no need to be opening another mdb every time there's an error.