Err.Source Property

Syntax

Err.Source

Description

A read-write string property containing the name of the application or the object that has generated the error.

Rules at a Glance

  • When a runtime error occurs in your code, the Source property is automatically assigned the project name (that is, the string that is assigned to the project's Name property). Note that this isn't necessarily the filename of the project file.

  • For clarity of your error messages, when you raise an error in a class module, the format of the source parameter should be project.class. You can use the App.Title property to obtain the project name.

Programming Tips and Gotchas

Knowing what type of error has occurred within a program is often of little use to you if you don't know where the error was generated. However, if you enhance the standard Source by adding the name of the procedure, your debugging time can be cut dramatically.

See Also

Err Object, Chapter 6

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.