Introduction to User Defined Procedures

In previous chapters, you learned how to use built-in VBA functions (also known as procedures) such as MsgBox and InputBox. You may have wondered how those functions were implemented. In this section, you learn how to build your own functions using user-defined procedures.

Access VBA supports three types of procedures: subprocedures, function procedures, and property procedures. I specifically discuss subprocedures and function procedures while saving property procedures for Chapter 10, "Object Oriented Programming with Access VBA," when I discuss object-oriented programming, also known as OOP!

Though different in implementation and use, both subprocedures and function procedures share some characteristics, such as beginning and ending statements, executable statements, and incoming arguments. The main difference between the two revolves around a return value. Specifically, subprocedures do not return a value, whereas function procedures do.

User-defined procedures are added to your Visual Basic code modules manually or with a little help from the Add Procedure dialog box. To access the Add Procedure dialog box, open your VBE (Visual Basic Environment) and make sure the Code window portion has the focus. Select Insert, Procedure from the menu.

The main difference between subprocedures and function procedures is that subprocedures do not return values. Many other programming Languages, such as C or Java, simply refer to a procedure that returns no value as a void function.

0 0

Post a comment