Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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
				

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Keywords: KB225878, kbprb, kbprogramming

↑ Back to the top

Article Info
Article ID : 225878
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 325