EXERCISE TOPIC▼
- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Power Platform exercises ()
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
ACCESS EXERCISES▼
ACCESS VBA MACROS EXERCISES▼
Access VBA Macros | Creating functions exercise | Write a function to show how long someone lived
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
Software ==> | Access VBA Macros (25 exercises) |
Version ==> | Access 2010 and later |
Topic ==> | Creating functions (4 exercises) |
Level ==> | Relatively easy |
Subject ==> | Access training |
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
The aim of this exercise is to show a list of actors who are no longer with us, sorted by how long they were alive:

Whoever knew Zsa Zsa lived so long?
To do this, create a function called YearsLived which will have two input arguments:
Argument | What it will hold |
---|---|
BirthDate | The date someone was born |
DeathDate | The date someone died |
Think carefully not only what data type you should assign to these arguments, but also what data type the function should return.
Use the DATEDIFF function to determine someone's lifespan in years from these two bits of information, and return this from your function. The syntax is:
Test that your function works in the immediate window, then incorporate it into a query to show the years each actor was alive (only shows actors whose DoD field is not null). Zsa Zsa Gabor lived the longest; who lived the shortest number of years?
Save and close any queries, modules or tables you have open.