Now that you have a sample database, I return to a discussion of modules and procedures. You already saw a procedure inside the sample module illustrations provided previously, but let's now analyze what the procedures are and how they can be used.
Procedures are the building blocks of modules. Each module contains one or more sub procedures or functions, and each sub procedure or function contains one or more VBA code statements.
Procedures can either be sub procedures or function procedures. A sub procedure performs an action but does not return a particular result. A function performs an action and returns a particular result. I will provide various examples to illustrate these differences. Sub procedures and functions can be called both from within other procedures and functions and when an event associated with an object is triggered (for example, button_click), as I describe in more detail in Chapter 3.
The syntax for declaring a new sub procedure without parameters is:
Sub ProcedureName 'code for the procedure End Sub
The syntax for a new sub procedure that contains variables as parameters is:
Sub ProcedureName(Variables) 'code for the procedure End Sub
Variables are containers for storing data. If a procedure must use the value stored in a particular variable, that variable can be passed as a parameter to the procedure. Let's create a new procedure to ...