Software

Let Access calculate field values for you

There's no point in manually calculating a field based on the value in another field. With this simple form trick, you can have Access perform the calculation automatically.

When a field needs to be calculated using data from another field, you don't have to perform the calculation yourself. You can create a form that automatically calculates the field for you. For example, after entering a product discount in a form, you want Access to update the discount price field automatically (Figure A).

Figure A

field update

Follow these steps:

  1. Open the form in Design View.

  1. Right-Click the Discount field.

  1. Click on the Event tab and click the Build button of AfterUpdate property box (Figure B).

Figure B

AfterUpdate property

  1. Enter the following code at the prompt (Figure C):

Private Sub Discount_AfterUpdate()
    [Discount Price] = [UnitPrice] * (1 - [Discount])
End Sub

Figure C

update code

  1. Press Alt + Q.

Now, when a discount is entered in the Discount field, the Discount Price field will automatically update with the new price.


Miss an Access tip?

Check out the Microsoft Access archive and catch up on other Access tips.

Help users increase productivity by automatically signing up for TechRepublic's free Microsoft Office Suite newsletter, featuring Word, Excel, and Access tips, delivered each Wednesday.

Editor's Picks