Table of contents
TOC
Collapse the table of content
Expand the table of content

Source Property (Visual Basic for Applications)

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Returns or sets a string expression specifying the name of the object or application that originally generated the error. Read/write. Remarks The Sourceproperty specifies a string expression representing the object that generated the error; theexpression is usually the object'sclass name or programmatic ID. Use Source to provide information when your code is unable to handle an error generated in an accessed object. For example, if you access Microsoft Excel and it generates a Division by zero error, Microsoft Excel sets Err.Number to its error code for that error and sets Source to Excel.Application. When generating an error from code, Source is your application's programmatic ID. Forclass modules, Source should contain a name having the form project.class. When an unexpected error occurs in your code, the Source property is automatically filled in. For errors in astandard module, Source contains theproject name. For errors in a class module, Source contains a name with the project.class form.

Example

This example assigns the Programmatic ID of an Automation object created in Visual Basic to the variable MyObjectID, and then assigns that to the Source property of the Err object when it generates an error with the Raise method. When handling errors, you should not use the Source property (or any Err properties other than Number ) programmatically. The only valid use of properties other than Number is for displaying rich information to an end user in cases where you can't handle an error. The example assumes that App and MyClass are valid references.

Dim MyClass, MyObjectID, MyHelpFile, MyHelpContext
' An object of type MyClass generates an error and fills all Err object
' properties, including Source, which receives MyObjectID, which is a 
' combination of the Title property of the App object and the Name
' property of the MyClass object.
MyObjectID = App.Title &; "." &; MyClass.Name
Err. Raise    Number := vbObjectError + 894, Source := MyObjectID, _
                Description := "Was not able to complete your task", _
                HelpFile := MyHelpFile, HelpContext := MyHelpContext 
© 2018 Microsoft