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