Exercises


1. 

What is a module, and what are the different types of modules?

image from book

2. 

What is the difference between a sub procedure and a function? When should you use each one?

image from book

3. 

Describe at least three ways you can control the flow of code execution. Also describe how variables fit into controlling the flow of code execution.

image from book

4. 

Implementing naming conventions and code documentation are both good habits to practice. What value do they provide?

image from book

5. 

Describe the types of errors that you might encounter in your application and how to resolve them so that the program will operate and will provide users with informative error messages.

image from book

Answers

1. 

A module is a storage container for your VBA code. Modules can either be standard modules or class modules. Standard modules are not associated with a particular object. Class modules can either be associated with forms or reports or be based on custom-defined objects.

2. 

A sub procedure performs a particular action. A function performs a particular action and also returns a particular result. When you need to obtain some type of result based on the action, such as a value that was calculated, you should use a function. An example of a function is one that calculates sales tax and returns the sales tax amount. An example of a procedure is one that displays a message to the user or runs a database update.

3. 

You can control the flow of code execution using If Then statements, Select Case statements, loops, conditional If statements, and IIf statements, as a few examples. Variables can be declared to store various values. Variables can then be used as part of the statements that control code execution to determine if certain conditions are met or whether certain actions should be taken.

4. 

Naming conventions involve naming your variables and objects in a particular way, such as with prefixes, which makes them easier to understand without tracking down the declaration or first use in code. Code documentation is important to illustrate how your program works and makes it much easier for you and others to debug and maintain the program in the future. Ideally, your code should be documented at the procedure level to describe how the procedure works, as well as with inline comments that explain how segments of code operate.

5. 

When writing VBA code, you will encounter various types of errors, such as syntax errors, runtime errors, compile errors, and logic errors. Syntax errors occur when you have not specified the correct language syntax. Compile errors occur when the program will not compile for some reason, although the syntax may be correct. Runtime errors occur when the program runs and encounters a scenario that is not allowed or expected. Logic errors are mistakes that are made in the logic itself such that the code does not perform the operation as intended. You can use various techniques from the Visual Basic Editor to eliminate most of these errors. A well-designed application should also include error handling that will capture and display informative error messages to users of the program so they do not get those nasty error messages.




Beginning Access 2007 VBA
Beginning Access 2007 VBA
ISBN: 0470046848
EAN: 2147483647
Year: 2004
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net