0% found this document useful (0 votes)
13 views2 pages

Calculated Field

How to get calculated fields in excel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Calculated Field

How to get calculated fields in excel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

To add a **calculated field for age** in a form in Microsoft Access, which is

calculated by subtracting the year of birth from the current year, follow these
steps:

### Step-by-Step Procedure:

#### 1. **Open Your Form**:

- Open the form in **Design View** where you want to add the calculated
field for age.

#### 2. **Add a New Text Box**:

- In **Design View**, click on the **Text Box** control from the **Design**
tab (you'll find it under the "Controls" section).

- Click on the form where you want to place the calculated age field.

#### 3. **Set the Control Source**:

- Right-click the newly added text box and select **Properties**.

- In the **Control Source** property, you will need to enter a calculation for
the age based on the date of birth.

Assuming the **YearOfBirth** field stores the user's birthdate, enter the
following formula to calculate the age:

```sql

=DateDiff("yyyy", [YearOfBirth], Date()) - IIf(Format([YearOfBirth], "mmdd")


> Format(Date(), "mmdd"), 1, 0)

```

**Explanation of the formula**:


- `DateDiff("yyyy", [YearOfBirth], Date())`: This calculates the difference in
years between the current date and the date of birth.

- `IIf(Format([YearOfBirth], "mmdd") > Format(Date(), "mmdd"), 1, 0)`: This


part adjusts the age if the current date hasn't reached the birthday yet in the
current year (i.e., if the birthday hasn't occurred yet).

#### 4. **Name the Text Box**:

- To make the field more readable and understandable, you may want to
give the text box a meaningful name. In the **Name** property of the text
box, you can name it `txtAge` or something similar.

#### 5. **Format the Output (Optional)**:

- You can adjust the appearance of the text box by setting properties like
**Font**, **Font Size**, and **Text Alignment** as needed.

#### 6. **Save and View the Form**:

- After setting up the calculated field, switch to **Form View** to see how
the calculated age appears for each record.

### Important Notes:

- Ensure that the **YearOfBirth** field in the table is in **Date/Time** format.

- The calculation will automatically update the age whenever the form is
opened or the record is refreshed.

By following these steps, you'll be able to dynamically calculate and display


the age of a person in the form based on their date of birth.

You might also like