Microsoft Access
Revision of VBA exercise
Average difficulty

This Microsoft Access REVISION OF VBA 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: Access form - looping over controls

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

1) Download the files needed to start this exercise: exercise-417.zip (and click here if you experience any problems unzipping this file after downloading it).
2) Consider the form called Results:
Exercise screen-shot 648 Clearly Chelsea would not normally lose like this ...
3) In a separate module, write a macro which:
  • Opens the form called Results in design view (use DoCmd.OpenForm)
  • Sets an object variable to refer to this form
  • Loops over all of the controls in this form, deciding for each whether it is a label, a textbox or something else, and adding 1 to the appropriate total
  • Writes out the final statistics
4) The output from your macro should look like this:
Exercise screen-shot 649 The 2 other controls are actually combo boxes
Training exercise hint To find the type of a control, use a command like: IF TypeOf c Is TextBox THEN
5) Run your macro to check it works!

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 copyright Wise Owl Business Solutions Ltd 2008.  All rights reserved..