Require variable declarations for Visual Basic code

Require variable declarations for Visual Basic code

Microsoft Visual Basic doesn't automatically require that you explicitly declare a variable before using it in a procedure. If you use a variable that hasn't been explicitly declared, Visual Basic 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. To require that variables be declared before they are used in a procedure, do the following:

  1. On the Tools menu, click Options.

  2. Click the Editor tab.

  3. Under Code Settings, select the Require Variable Declaration check box.

    When the Require Variable Declaration check box is selected, Microsoft Access automatically includes an Option Explicit statement in the Declarations section of all new modules in the database, including the form and report modules associated with new forms or reports. For more information on the Option Explicit statement, click .