ACC2000: Option Explicit Does Not Appear in New Modules by Default (225878)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q225878
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

When you create a new module in Microsoft Access 2000, Option Explicit does not appear in the Declarations section of the module. By default, only the following line appears in new modules:
   Option Compare Database
				

In earlier versions, the following two lines appeared in new modules by default:
   Option Compare Database
   Option Explicit
				

CAUSE

All Microsoft Office 2000 applications share the same interface for editing Visual Basic for Applications code. The Visual Basic Editor is a new interface for editing Visual Basic for Applications code in Access 2000. The editor uses the same default settings as Microsoft Visual Basic and earlier versions of other Microsoft Office applications that used the editor.

RESOLUTION

In order to have Option Explicit automatically inserted into new modules, turn on the Require Variable Declaration option in the editor.
  1. To open the editor, click Macro on the Tools menu, and then click Visual Basic Editor. The keyboard shortcut to open the editor is ALT+F11.
  2. Click Options on the Tools menu.
  3. Click the Editor tab.
  4. Click to select the Require Variable Declaration option.
  5. Click OK.

    Now when you create a new module, Option Explicit will automatically appear in the module.

MORE INFORMATION

Existing modules are not effected by the Require Variable Declaration setting.

Visual Basic for Applications does not automatically require that you explicitly declare a variable before using it in a procedure. If you use a variable that has not been explicitly declared, Visual Basic for Applications implicitly declares it as a variable with the Variant data type. Although implicit declarations are convenient, they can lead to subtle errors in your code.

Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.

Modification Type:MajorLast Reviewed:6/24/2004
Keywords:kbprb kbprogramming KB225878