ACC: Variable Not Defined Error with Yes/No Arguments

Last reviewed: May 21, 1997
Article ID: Q140288
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

Moderate: Requires basic macro, coding, and interoperability skills.

SYMPTOMS

When you use a Yes or a No argument with a method of the DoCmd object, you may receive the following error message when you attempt to compile the module:

   Variable not Defined.

CAUSE

When you use a method of the DoCmd object in Visual Basic for Applications, Microsoft Access 7.0 and 97 will not accept a Yes or No argument. Yes and No are not system-defined constants. Unless otherwise user-defined, their values are Null.

RESOLUTION

Use True or -1 for the argument instead of Yes, and use False or 0 (zero) instead of No.

True and False are system-defined constants in Microsoft Access 7.0 and 97. The value of the constant True is -1, and the value of the constant False is 0. You can use the constant and its value interchangeably.

MORE INFORMATION

Most macro actions have a corresponding Visual Basic for Applications method for the DoCmd object. In macro actions, many times Yes and No are used in the different action arguments.

When you use methods of the DoCmd object, however, you must use either a system-defined constant, the underlying value of the constant, or a user- defined variable or constant that has been assigned the appropriate value.

Steps to Reproduce Behavior

  1. Open a Visual Basic for Applications module and type the following function:

          Function TestYesNo()
    
             DoCmd.Setwarnings Yes
          End Function
    
    

  2. On the Run menu, click Compile Loaded Modules. Note that you receive the compile error "Variable not Defined" for the Yes argument.

  3. Change the function to read as follows:

          Function TestYesNo()
    
             DoCmd.Setwarnings True
          End Function
    
       Note that this function compiles and work correctly.
    
    

REFERENCES

For more information about system-defined constants, search the Help Index for "constants, system-defined," or ask the Microsoft Access 97 Office Assistant.


Keywords : ExrOthr kberrmsg kbusage
Version : 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.