Chapter 9. Understanding Scope and Lifetime

IN THIS CHAPTER

Scope Explained 117

Measuring the Lifetime of a Variable or Constant 121

Using Static Variables 124

Case Study: Tracking the Current User 126

Scope Explained

The dictionary defines scope as extent of treatment, activity, or influence; range of operation. In VBA terms, scope covers where, within your VBA, a variable can operate or have influence. In Chapter 5, “Building Procedures,” in the section “Public Versus Private,” we discussed the scope of procedures. Variables function similarly using the concepts of scope and lifetime. A variable’s scope defines how other code within your application can see it. The lifetime of a variable dictates when it contains valid data.

A variable’s scope ...

Get Microsoft® Office Access 2007 VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.