Chapter 13: Accessing Data with VBA Code
515
At the end of the procedure, txtTaxAmount is set to the curTaxAmount value.
When the Buyer, Tax Location, or Tax Rate controls are changed in frmSales, you use the
AfterUpdate event for the individual control to recalculate the tax amount. Figure 13.18 shows
the code for the txtTaxRate_AfterUpdate event.
FIGURE 13.18
Recalculating a control after a control is updated
The logic implemented in txtTaxRate_AfterUpdate is identical to the logic in fsubSales-
LineItems_AfterUpdate. In fact, you can use the same code for the Buyer and Tax Location
controls as well. The only difference between the code in Figure 13.16 and the code in Figure
13.18 is that the procedure in Figure 13.16 runs whenever a change occurs in the sales line items
subform, while the code in Figure 13.18 runs whenever a change is made to txtTaxRate on the
main form.
Checking the status of a record deletion
Use the form’s AfterDelConfirm event to recalculate the txtTaxAmount control when delet-
ing a line item. The form’s AfterDelConfirm event (shown in Figure 13.19) is similar to the
code for the subform’s AfterUpdate event. Notice however, that txtTaxAmount on the main
sales form is set by this procedure, even though this code runs in fsubSalesLineItems sub-
form embedded on frmSales.
Access always confirms deletions initiated by the user. Access displays a message box asking the
user to confirm the deletion. If the user affirms the deletion, the current record is removed from
the form’s recordset and temporarily stored in memory so that the deletion can be undone if neces-
sary. The AfterDelConfirm event occurs after the user confirms or cancels the deletion. If the
BeforeDelConfirm event isn’t canceled, the AfterDelConfirm event occurs after the delete
confirmation dialog box is displayed. The AfterDelConfirm event occurs even if the
BeforeDelConfirm event is canceled.