Learn Access 2003 VBA with The Smart Method
76
www.LearnAccessVBA.com
Lesson 4-3: Understand step
over and step out
1
Begin in exactly the same way as the previous lesson by
setting a breakpoint at the line
Call ThankYouMessage
.
2
Return to the form and Click the cmdPressMe command
button.
You are transferred to the code editor with code execution halted
at the breakpoint.
3
Click the Step Over button
on the debug toolbar.
An audible Beep is heard as the code in ThankYouMessage
executes and the Message Box is immediately displayed.
This happened because the code in the ThankYouMessage sub will
execute as normal and will not be stepped through as we
requested that VBA stepped over the subroutine.
Click the OK button and execution halts at End Sub in the
cmdPressMe_Click event handler.
This is very useful when you want to examine the way code is
executed in a single sub but have no interest in the code within any
other subs that it may call.
4
Click the Step Over button
(or Step Into button
) on
the Debug Toolbar.
Session4a
pg_0002
Session Four: An Introduction To VBA
© 2007 The Smart Method Ltd
77
Nothing happens as all code has executed. In this case Step Into
and Step Over will result in exactly the same action.
5
Click the cmdPressMe command button.
You are transferred to the code editor with code execution halted
at the breakpoint.
6
Click the Step Into button
on the Debug Toolbar twice.
The code steps into the ThankYouMessage sub procedure header
and then to the line saying Beep.
7
Click the Step Out button
on the Debug Toolbar once
more.
An audible Beep is heard as the code executes and the message box
is immediately displayed.
8
Click the OK button on the displayed message box.
Code execution is now halted at the next line of code in the
cmdPressMe_Click event handler. The Step Out button has
executed all remaining code in the ThankYouMessage sub
procedure without stopping and then paused on the next
executable line of the calling sub procedure—cmdPressMe_Click.
Step Out is very useful when you are no longer interested in the
remaining code within the current sub but want to examine how
the remainder of the code in the calling sub will execute.