Source Method

Returns or sets the name of the object or application that originally generated the error.

Syntax

object.Source

Arguments:

Object: Required.Always the Err object.

Remarks

The Source property specifies a string expression that is usually the class name or programmatic ID of the object that caused the error. Use Source to provide your users with information when your code is unable to handle an error generated in an accessed object. For example, if you access code that generates a Division by zero error, Err.Number set to its error code for that error.

Source always contains the name of the object that originally generated the error — your code can try to handle the error according to the error documentation of the object you accessed. If your error handler fails, you can use the Err object information to describe the error to your user, using Source and the other Err to inform the user which object originally caused the error, its description of the error, and so forth.

When generating an error from code, Source is your application's programmatic ID.

The following code illustrates use of the Source method.

Example 1:

Sub RaiseUserDefinedError()
    On Error Resume Next       ' Enable error handling.
    Err.Raise 1, "SomeObject", "A custom error description."
     Output =  "Error # " & Err.Number & ": " & Err.Description & " Source: " & Err.Source
    Err.Clear                  ' Clear the error.
End Sub
'Output : Error # -1: A custom error description. Source: SomeObject