Access VBA Macro Programming

(Joao Candeias) #1

You can insert a breakpoint where you want to start checking the code and then single-step
the procedure to see what each statement is doing. You can also skip a statement or start
execution from a different place.


Single Stepping


Single stepping allows you to execute one statement at a time. You can place your cursor on
variables anywhere in the code to see the state of variables, and you can also use the Debug
window to view values of variables.
You can single-step by using Debug | Step Into from the menu or pressingF8. You can also
run the code to the position of the cursor. Click the mouse on a line of code and then press
CTRL+F8. The code will only execute as far as where you have clicked the mouse. Note that
the cursor must be on an executable line of code, not a blank line. You can also step between
individual statements if they are on the same line but separated by the:character.


temp = 4: If temp = 3 Then Exit Sub


Procedure Stepping


If you have a subroutine or function that is being called, you may not wish to step through the
whole procedure line by line. You may have already tested it and be satisfied with its performance.
If you useF8to step through (Single Step), you will be taken all through the subroutine’s code
one step at a time. This could be extremely time-consuming for something that you know already
works. If you useSHIFT+F8(Step Over), then your subroutine will be treated as a single statement
but without stepping through it.


Call Stack Dialog


The Call Stack dialog box, shown in the following illustration, displays a list of active
procedure calls—that is, calls that have been started but not completed. You can display this
dialog by usingCTRL+L,but it is only available in Break mode. It can help you trace the
operation of calls to procedures, especially if they are nested where one procedure then calls
another procedure.


Chapter 7: Debugging 85

Free download pdf