Access VBA Macro Programming

(Joao Candeias) #1

Chapter 7 Debugging


Chapter 7 Debugging


I


n any code you write, bugs may exist that can cause a program failure, cause the
program to hang, or simply create unexpected results. In my opinion, this area separates
the true analytical programmers from those who just type in code and hope it works.
Many reports have been written about “computer rage,” where users of an application get
upset because the results are different from what they expected. All I can say to those people
is wait until you work on code for an application like Access! You will then realize how
straightforward and well organized this application is. Once you have tried your hand at
fixing a few bugs in what appears to be a simple program, you will appreciate what goes on
behind the scenes when you click a menu selection or press an OK button.


Types of Errors


Errors occur very easily when you are writing code. This section gives you examples of the
types of errors you can expect to see.


Compile Errors


Compile errors result from incorrectly constructed code. You may have used a property or
method that does not exist on an object, or put in a For without a Next or an If without an
End If.
When you run code, the compiler goes through the code first and checks for these types
of errors. If any are found, the code will not be run, but an error message will be displayed
referring to the first error found. Note that there could be several compile errors in a procedure,
but only the first one will be flagged. You might correct the error and think, “I’ve fixed it


81

Free download pdf