Microsoft KB Archive/96577

{|
 * width="100%"|

PRB: Macro Condition Evaluates True If Control Is Null
'Article ID: Q96577

Creation Date: 22-MAR-1993

Revision Date: 03-FEB-1997' The information in this article applies to:


 * Microsoft Access versions 1.0, 1.1, 2.0, 7.0

SYMPTOMS

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

A macro that conditionally checks the contents of a control on a form always evaluates as True if the control is Null.

RESOLUTION

Include a StopMacro macro action with a condition to test the control for Null. If the control is Null, the macro will stop. If it is not Null, the second macro action will occur. This will be the action that you want to occur if your condition is met.

MORE INFORMATION

If you do not test for the Null condition, the macro will evaluate to True.

Steps to Reproduce Behavior

Create a new form not based on any table or query named Form1. Add a text box control to the form named Field0. Create and save the following macro named Test: Macro Name   Condition           Action Test         [Field0] = &quot;yes&quot;    MsgBox MsgBox Arguments Message: The Answer is YES! Beep: Yes Switch to Design view of the Form1 form and add a command button to the form. Set the OnClick property to the Test macro. NOTE: In version 1.x, the OnClick property is called the OnPush property. Switch to Form view and run the macro by clicking the command button. Note that Field0 is Null. (The message box should appear). Type the word &quot;NO&quot; in Field0 and rerun the macro (no Message box will appear). Type the word &quot;YES&quot; in the field and run the macro (Message box should appear). To correct this situation, change the Test macro so that it includes the StopMacro action before the MsgBox action as follows:

Macro Name   Condition           Action ---     Test          [Field0] Is Null    StopMacro [Field0] = &quot;yes&quot;   MsgBox


 * }

-

"THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED &quot;AS IS&quot; 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." '' ©1997 Microsoft Corporation. All rights reserved. Legal Notices.

''

KBCategory: kbusage

KBSubcategory: McrCond

Additional reference words: 1.00 1.10 2.00 7.00