Modifying existing code

After you either copy and paste code or import a module, modifying that code isn't all that different from writing new code, because you still have to know the exact meaning and syntax of every keyword used in the code. In some cases, the existing code might work as-is in your database. In other cases, you might have to edit the code to get it to work.

If you need to modify the code, you can't do so unless you understand what the code is doing and how it works. Thus, you have to know the purposes of each statement. If you need to change a statement, you need to know the correct syntax. Like when you're writing code, you can get more information about existing code by using either of these methods:

^ To see the Quick Info screen tip for a line of code, right-click the line and choose Quick Info.

^ For detailed help with a keyword, select (double-click) that keyword and press F1 to see the Help window.

Modifying existing code takes almost as much skill and knowledge as writing your own code from scratch, so don't expect to be able to get anything accomplished by taking wild guesses. You can see examples of modifying existing code throughout this book. For now, just be aware that you can copy and paste VBA code into a module. Or, if the code is already in some other database's module, you can import that module into your current database.

In Chapter 4, you can pick up more advanced skills for creating procedures. For now, be aware that every VBA keyword has certain rules of syntax, which you must follow to a T if you want your code to work. You can't expect to memorize and master every keyword and its syntax in a short time because VBA has too darn many keywords. However, after you know how to get help with keywords, you always have the information that you need at your fingertips.

0 0

Post a comment