Microsoft Office 2000/Visual Basic Programmer's Guide   

Returning Information About an Error

There are two ways of returning information about an error. The traditional VBA style is to raise the error in a procedure, either by leaving out an error handler so that the VBA error is returned to the calling procedure or by using the Raise method of the Err object. The other way to return error information uses the Windows application programming interface (API) style, where an error value is assigned to one of the procedure's parameters. For an example of using an API-style return value to get information about an error, see the ErrorExample2 procedure, available in the modErrorCode module in ErrorHandlers.dot in the ODETools\V9\Samples\OPG\Samples\CH08 subfolder on the Office 2000 Developer CD-ROM.

If you use the API style of returning error information, the calling procedure must use in-line error handling to identify whether an error has occurred. If you use the traditional VBA style, the calling procedure can use either in-line error handling or an error handler. Neither way is inherently better than the other. The important point to remember is to adopt a style that works for you and to use it consistently.