• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 15. Debugging: Your Key to Succe... > Looking At Gotchas with the Immediat...

Looking At Gotchas with the Immediate Window

Although the Access debugger is excellent, the debugging process itself is wrought with an array of potential problems, as follows:

  • The debugging process can interrupt code execution, especially when forms are involved. When this occurs, the best bet is to place Debug.Print statements in your code and examine what happens after the code executes.

  • Along the lines of the previous problem, it is difficult to debug code where you have coded the GotFocus and LostFocus events. Moving to the VBE triggers the LostFocus event of the control. Returning to the form causes Access to trigger the GotFocus event of the control. Once again, a great solution is Debug.Print. You also might consider writing information to an error log for perusal after the code executes.

  • You cannot successfully execute many methods of the DoCmd object during the debugging process. An example is DoCmd.RunCommand accmdSaveRecord. When executed in the debugger, this line of code renders the error shown in Figure 15.21.

    Figure 15.21. An error results when executing the RunCommand method of the DoCmd object while the debugger is active.

  • Code that uses Screen.ActiveForm and Screen.ActiveControl wreaks havoc on the debugging process. When the VBE is active, there is no active form and no active control. Avoiding these lines in your code wherever possible alleviates this problem.

  • Finally, be aware that resetting code can cause problems. If you are modifying environmental settings, you are left with whatever environmental settings your application code changed. If you continue execution after the error without resetting, all sorts of other problems can occur. It is a good idea to code a special utility routine that resets your environment.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint