Mark,
Would something like this work for you?
This is an example of an error handler that I typically use:
Thanks Troy, I'm sure it works great, once I understand the code I'm sure I'll appreciate it even more.
On Error Goto ErrorHandler
This line is the key. It tells the compiler what to do when an error occurs. In this case it tells the compiler to go to the label "ErrorHandler" i.e. program execution continues on the line immediately following the label. It is similar to the statement "On Error Resume Next" which tells the complier that if an error occurs skip to the next line after where the error occured.
Keep in mind a label should not be used under normal circumstances as it can lead to code that is difficult to maintain. However, I have found them extremely useful for handling errors as I can group all of the error handling code in one location instead of having it strewn about the rest of the routine.
This next bit of code is the heart of the error handler. It consists of two pieces, the part that allows the program to clean up after itself (close DB connections, dispose of objects, etc.).
ExitHere:
'clean up any references...
set oPoint = nothing
exit function
In the "ExitHere" section you will place code that you want to run to make sure that routine exits properly. In the normal course of things, your program would natural flow into the "ExitHere" section and end gracefully. There might be situations where you need to terminate your application early, but you still want to make sure everything is cleaned up.
So instead of using somthing like this:
if oPoint is nothing then exit function
You could use something like:
if oPoint is nothing then goto ExitHere
The last part of the routine is invoked when an error occurs:
ErrorHandler:
select case Err.number
case -22222 '<-This would be where the error that is thrown from the .Find method
resume next 'resume on the line following where the error was thrown
case else
msgbox "Something just happened... " & err.number
end select
resume ExitHere
end function
When an error occurs, the "On Error Goto ErrorHandler" is followed and the program continues execution on the line immediately following the "ErrorHandler" label. In this case, the select statement. What your interested in is trapping the error generated by the find method. That is why I have "case -2222" I don't know what error number is thrown. Instead of -2222 you would put the error number that is generated. The next line "resume next" tells the program to jump back up to the line immediately after the line that through the error.
Does that make sense? If you need a better explaination let me know and I'll see what I can whip up tonight.