Prev | Current Page 1522 | Next

Michael R. Groh, Joseph C. Stockman, Gavin Powell, and Cary N. Prague

"Access 2007 Bible"


The following procedure shows how error handling is implemented in VBA procedures:
Sub RoutineA()
On Error GoTo HandleError
MsgBox ???Now in routine A???
ExitHere:
MsgBox ???Now leaving routine A???
Exit Sub
HandleError:
MsgBox ???Error in routine A???
Resume ExitHere
End Sub
The On Error statement near the top of the procedure sets the error trap for the routine. Code
near the bottom of the routine implements the error-handling mechanism for this subroutine. The
error-handling code in this procedure is the very least you can include in your procedures to handle
runtime errors effectively. The error-handling statements in this procedure are the template you
can consistently use in all your VBA programs.
The On Error clause informs VBA that you want to defeat the built-in VBA error-handling system
by sending execution to the location identified by the ???HandleError??? label. The GoTo Label
statement is an unconditional branch (in the event of an error) to a label somewhere within the
procedure.


Pages:
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
geovision datowniki wanny prace magisterskie polish builders