Part II: Programming Microsoft Access
438
Figure 11.9 shows a typical subroutine. Notice the Sub keyword that begins the routine, followed by
the name of the subroutine. The declaration of this particular subroutine includes the Private key-
word, which restricts the availability of this subroutine to the module containing the subroutine.
FIGURE 11.9
A typical subroutine in an Access application
The subroutine you see in Figure 11.9 contains most of the components you’ll see in almost every
VBA sub or function:
l Declaration: All procedures must be declared so that VBA knows where to find them. The
name assigned to the procedure must be unique within the VBA project. The Sub key-
word identifies this procedure as a subroutine.
l Terminator: All procedures must be terminated with the End keyword followed by the
type of procedure that is ending. In Figure 11.9, the terminator is End Sub.
l Declarations area: Although variables and constants can be declared within the body of
the procedure, good programming conventions require variables to be declared near the
top of the procedure where they’ll be easy to find.