Raising Errors

The Raise statement can be used to generate run-time errors and can be used instead of the Error statement.
Using the Err object gives more information that the Error statement
If you want to use sound to indicate when something is wrong or incorrect you can use the statement Beep() function.
If you are generating errors, then you should add your number to the vbObjectError constant.
For any user defined errors, these should be greater than vbObjectError
Eg Err.Raise Number = vbObjectError + 1000


To generate a run-time error you can use the Raise method


Err.Raise(Number [, Source] [, Description] [, HelpFile] [, HelpContext])


Number
Long, identifying the type of the error. Visual Basic errors range from 0 to 65535
The range 0 - 512 is reserved for system errors
The range 513 - 65535 is available for user defined errors
Eg Err.Raise Number = vbObjectError + 1000


Source
String
If this is not specified then the programming ID of the current project is used.


Description
This the string that describes the error.
If the error can be mapped to a Visual Basic run-time error the string corresponding to the Number is ised.
If there is no Visual Basic error corresponding to the number then "Application-defined or object-defined error" message is used.


helpfile
The full path of the Help file in which the error can be found
If unspecified then the fully qualified drive, path and file name of the Visual Basic help file is used.


help context
The context ID that identifies the topic within the corresponding help file.
If omitted then the context ID for the error corresponding to the Number property is used if it exists.


ERROR Statement

There is also an ERROR statement that can be used to generate errors.
Although this is only provided for backwards compatibility.


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext