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.

Software ==> Advanced VBA  (33 exercises)
Version ==> Any MS Office versions
Topic ==> Passing arguments  (6 exercises)
Level ==> Average difficulty
Subject ==> VBA training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

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:

Advanced VBA exercise - Passing arguments (image 1)

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:

Advanced VBA exercise - Passing arguments (image 2)

This is how you might call your amended subroutine

Save this module and close the database.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post