Chapter 11: Mastering VBA Data Types and Procedures
441
FIGURE 11.10
The frmSales cboBuyerID_AfterUpdate event procedure in the VBA code window
The procedure behind this form runs each time the user selects a different buyer in cboBuyerID.
This code updates the value of the tax location and tax rate.
Creating Functions
Functions differ from subprocedures in that functions return a value. In the examples in this sec-
tion, you’ll see functions that calculate the extended price (quantity × price) for a line item, create a
function to calculate the total of all the taxable line items, and then apply the current tax rate to the
total.
Although functions can be created behind individual forms or reports, usually they’re created in
modules. This first function will be created in a new module that you’ll name basSalesFunc-
tions. Putting this function in a standard module makes it available to all parts of the applica-
tions. To do this, follow these steps:
- Select the Modules tab in the Navigation Pane.
- Right-click the basSalesFunctions module and select Design view from the context
menu.
The VBA window is displayed with the title basSalesFunctions (Code) in the title bar.