Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
On Error Statement

Syntax 1

On Error GoTo label|0

label

Use: Either label or 0 is required

A valid label within the subroutine.

Syntax 2

On Error Resume Next

Description

Enables or disables error handling within a procedure. If you don't use an On Error statement in your procedure, or if you have explicitly switched off error handling, the Visual Basic runtime engine handles the error automatically. First, it displays a dialog containing the standard text of the error message, something many users are likely to find incomprehensible. Second, it terminates the application, so any error that occurs in the procedure produces a fatal runtime error.

Rules at a Glance

Syntax 1

  • The argument disables error handling within the procedure until the next On Error statement is executed.

  • The label argument specifies the name of the label defining an error-handling routine within the current procedure that will be branched to should an error occur.

  • A subroutine label must be suffixed with a colon; furthermore, you can't use a VB, reserved word for a subroutine label name. For example:

    someroutine:
  • label must be in the same procedure as the On Error statement.

Syntax 2

  • When a runtime error occurs, program execution continues with the program line following the line that generated the error.

Programming Tips and Gotchas

  • If you have no error handling in your procedure or if error handling is disabled, the VB runtime engine traces back through the call stack until a procedure is reached where ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Absolute Beginner's Guide to VBA

Absolute Beginner's Guide to VBA

Paul McFedries
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 1565923588Catalog PageErrata