Using the Stop Statement

Sometimes you won't be able to test your procedure right away. If you set up your breakpoints and then close the database file, the breakpoints will be removed; next time, when you are ready to test your procedure, you'll have to begin by setting up your breakpoints again. If you need to postpone the task of testing your procedure until later, you can take a different approach. Insert a Stop statement into your code wherever you want to halt a procedure. Figure 9-8 shows the Stop statement before the With.. .End With construct. Visual Basic will suspend the execution of the cboEndDate_Change event procedure when it encounters the Stop statement and the screen will display the Code window in break mode. Although the Stop statement has exactly the same effect as setting a breakpoint, it does have one disadvantage. All Stop statements stay in the procedure until you remove them. When you no longer need to stop your procedure, you must locate and remove all the Stops.

Figure 9-8: You can insert a Stop statement anywhere in your VBA procedure code. The procedure will halt when it gets to the Stop statement, and the Code window will appear with the code line highlighted.