Source Property

Applies To   Error object.

Description

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

Return Values

The return value is a String representing the object or application that generated the error.

Remarks

The Source property value is usually the object's class name or programmatic ID. Use the Source property to provide your users with information when your code is unable to handle an error generated in an object in another application.

For example, if you access Microsoft Excel and it generates a "Division by zero" error, Microsoft Excel sets Error.Number to the Microsoft Excel code for that error and sets the Source property to Excel.Application. Note that if the error is generated in another object called by Microsoft Excel, Microsoft Excel intercepts the error and still sets Error.Number to the Microsoft Excel code. However, the other Error object properties (including Source) will retain the values as set by the object that generated the error. The Source property always contains the name of the object that originally generated the error.

Based on all of the error documentation, you can write code that will handle the error appropriately. If your error handler fails, you can use the Error object information to describe the error to your user, using the Source property and the other Error properties to give the user information about which object originally caused the error, the description of the error, and so forth.

Note The On Error Resume Next construct may be preferable to On Error GoTo when dealing with errors generated during access to other objects. Checking the Error object property after each interaction with an object removes ambiguity about which object your code was accessing when the error occurred. Thus, you can be sure which object placed the error code in Error.Number, as well as which object originally generated the error (Error.Source).

See Also   Description property.

Specifics (Microsoft Access)

The DAO Source property applies to the Error object and can be read only from Visual Basic.

Note   Don't confuse this property with the Microsoft Access Source property, which applies to a query and specifies the source connection string and source database for the query's input table or query.

Example

See the Description property example.