Using Enum
If you want to raise your own specific errors and have code to handle these errors you could put everything into a dedicated class.
Define all your errors using an Enum.
Use the vbObjectError built-in constant to ensure the custom error codes do not overlap with reserved/existing error codes.
The Err.Raise method can also take custom Description and Source parameters so it worth having a description associated with each error.
Create a dedicated private method to raise each error:
To raise the error, just call the correspnding subroutine.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext