A calculate control is a form object that performs some sort of calculation based on data in the form or data extracted from another source. Adding a calculated control is as easy as adding a text box. To demonstrate a control already in use, open the Orders form from the Northwind sample database:
The Subtotal and Total fields are both calculated controls. More specifically, they are text boxes that have a mathematical expression as their control source. Open the table in Design view and view the properties of the Total field:
The Control Source field has a simple expression that adds the Subtotal and Freight fields together and displays the result. It is important to note that in Form view, these text boxes cannot be altered. You cannot add data to them or change the values contained in them. If you look again at the Data tab of the text box, notice that the Locked field is marked as Yes, or true. You can lock a text box (or other object) from being edited using this control. Let’s make a basic (and completely impractical!) calculator using Access. Make a new form in Design view, and then add three text boxes:
Open the Properties dialogue box for the first text field, and click the Other tab. Enter value1 as its Name. Repeat for the second and third text boxes, naming them value2 and total respectively:
Change the Format of each text box to General Number (in the Format Tab). Click the Data tab for the total text box and enter =[value1]+[value2]. Now that the calculator is set up, switch back to Form view and enter some numbers:
|