Microsoft Access
Good programming techniques exercise
Relatively easy

This Microsoft Access GOOD PROGRAMMING TECHNIQUES exercise is provided to allow potential course delegates to assess their suitability for the Wise Owl ADVANCED VISUAL BASIC FOR APPLICATIONS course only, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Exercise: Subroutines taking arguments

A full answer to this exercise is provided as part of the training course!

1) In some suitable application (Excel, for example) create a simple subroutine to display a message.  Your subroutine should take one argument - the message to be displayed - and produce output like this:
Exercise screen-shot 2168 You can pass different messages to your subroutine to display different message boxes
2) If you still have time, try writing a different subroutine to unprotect or protect a given worksheet.  This subroutine should take 2 arguments:
  • The name of the sheet to be protected or unprotected
  • Whether to protect the sheet or not (a Boolean argument)
Training exercise hint Note that to protect or unprotect a worksheet you just apply the Protect or Unprotect methods. 
3) Try running your  macro using commands like this to test it:
Exercise screen-shot 2169 Two sample commands to test your macro
4) If you still have time, try making the second argument optional, so that by default your subroutine will protect a sheet if the protection status is not explicitly given when the macro is run.
5) Save this file as Examples of arguments, and close it down.

Thank you for showing an interest in this Advanced Visual Basic for Applications training course! As mentioned above, full answers to this and other exercises are provided on the course. On all Wise Owl scheduled courses delegates can take away these model answers (together with their own efforts!) on a free USB stick.

All content � Wise Owl Business Solutions Ltd 2007.  All rights reserved.  Design by Branches.