Used at module level to force explicit declaration of all variables in that module.
Option Explicit
If used, the Option Explicit statement must appear in a module before any statements that declare variables or define constants.
If you don’t use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.
When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.
Tip Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid risking confusion in code where the scope of the variable is not clear.
Const Statement, Deftype Statements, Dim Statement, Function Statement, Option Base Statement, Option Compare Statement, Option Private Statement, Private Statement, Public Statement, ReDim Statement, Static Statement, Sub Statement.
In Microsoft Access, you can ensure that all new form modules, report modules, and standard modules will automatically include the Option Explicit statement. On the Tool menu, click Options, then click the Module tab, and select the Require Variable Declaration option.
Once you select this option, it will automatically be set for all other databases which you create or open with Microsoft Access.
Note When you select this option, only new modules will have the Option Explicit setting. You must enter the Option Explicit statement into the Declarations section of any existing modules; or when the module is open, on the Tools menu click Options, click the Module tab, and select the Require Variable Declaration option.
This example uses the Option Explicit statement to force you to explicitly declare all variables. Attempting to use an undeclared variable causes an error at compile time. The Option Explicit statement is used at the module level only.
Option Explicit ' Force explicit variable declaration.MyVar ' Declare variable.= 10 ' Undeclared variable generates error.= 10 ' Declared variable does not generate error.