Procedure Types

VBA has three types of procedures: subroutine, function, and property.

■ Subroutine procedures (subroutines, subprocedures)

These procedures perform useful tasks, but never return values. They begin with the keyword Sub and end with the keywords End Sub. Keywords are words that carry a special meaning in Visual Basic. Between these keywords you place the VBA instructions (statements) the procedure needs to execute. You can pass information to a procedure using arguments, which are the values that are needed for a procedure to do something. One or more arguments are entered after the procedure name. Multiple arguments are separated by commas.

Subroutines are written from scratch in modules located in the Visual Basic Editor window. You can also invoke the built-in Command Button Wizard from the toolbox in the Design view to automatically write procedures that automate database maintenance, form and report operations, record navigation, and other tasks.

■ Function procedures (functions)

Functions perform specific tasks and can return values. They begin with the keyword Function and end with the keywords End Function. Because functions return values, you can use them in expressions. Similar to procedures, functions can accept arguments. Function procedures can be executed from a subroutine.

Part I

■ Property procedures

Property procedures are used with custom objects. With property procedures you can set and get the value of an object's property or set a reference to an object.

0 0

Post a comment