ACC2: Form and Report Modules Have Local ScopeLast reviewed: April 2, 1997Article ID: Q112726 |
The information in this article applies to:
SUMMARYModerate: Requires basic macro, coding, and interoperability skills. This article describes the effect of "scope" of procedures and variables in form and report modules. Scope refers to the extent to which an identifier (that is, a constant, data type, variable, or routine) can be referenced in a program.
MORE INFORMATIONThe procedures and variables defined in a form or report module have "local" scope; that is, they and their values do not exist outside of that object. Attempting to call a function in a form or report module outside that form or report results in a "reference to undefined function or array" error message or other "unknown function name..." type of error. A call made to a subroutine from outside the form or report results in a "syntax error" message. A reference to one of the form's variables from a different module produces unexpected results. Due to the nature of modules and procedures, a new variable of the same name is implicitly created with an Empty value (Variant type 0). If Option Explicit has been specified in the module that refers to the form's variable, then a "Variable not Defined" compile error occurs. When you plan to create a procedure or variable in a form or report module, first determine that nothing outside of that form or report will require that the procedure or variable exist. Any variable or procedure you write in a form or report module should be useful to that form or report only. If you need to call a procedure from multiple forms or reports, place the procedure in a global module. Do the same for any variables your code needs to access from more than one form or report. The following example demonstrates the scope of a function in a form module and the errors that can occur:
REFERENCESMicrosoft Access "Building Applications," version 2.0, pages 59-60
|
Additional query words: cbf code behind forms
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |