ADVANCED VBA EXERCISES▼
Advanced VBA | Passing arguments exercise | Optional arguments - adding people
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.
You can learn how to do this exercise if you attend one of more of the courses listed below!
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.
Create an enumeration to hold the possible department ids:
If your trainer has forgotten to tell you what an enumeration is, tell him/her off!
Write a macro to add a new person to your database. You can assume that each person is in the Accounts department, which means setting the DepartmentId field to Department.Accounts. You can ignore the Address field). The macro should have two arguments:
- FirstName - the person's first name
- LastName - the person's last name
Test that your macro works by calling it from either the immediate window or from another subroutine to add the following people:
- Basil Brush
- Tom Thumb
Amend your subroutine so that, optionally, you can specify an extra argument giving the postcode. This should default to NOT SET if not specified. Call this amended subroutine to add the following people:
- Dave Cameron, W1
- Susan Dunne, IP33
- Luke Skywalker
If you have time, amend your macro so that you can also pass in (optionally) the department, which again defaults to Accounts:
This is how you might call your amended subroutine
Save this module and close the database.