Microsoft KB Archive/100126

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

PRA: RunMacro May Not Work with Large Repeat Count

Article ID: Q100126
Creation Date: 16-JUN-1993
Revision Date: 19-SEP-1996 The information in this article applies to:

  • Microsoft Access versions 1.0 and 1.1

SYMPTOMS


When you try to execute a RunMacro action with a Repeat Count argument greater than 32,767, either Microsoft Access may use an unexpected Repeat Count argument or the following error message may appear:

   Repeat Count argument in RunMacro action can't be less than 0

CAUSE

Microsoft Access does not explicitly check for Repeat Count arguments greater than 32,767. Such values may wrap around either to a negative number or to an unexpected positive number. If the resulting value is negative, Microsoft Access displays the above error message. If the value is positive, Microsoft Access runs the macro using the Repeat Count argument that it evaluated.

RESOLUTION


Make sure that your Repeat Count argument falls between 0 and 32,767. If you need to run a macro more than 32,767 times, nest your macros. For example, if you need to run a macro 60,000 times, use the following three steps:

  1. Create a macro (Macro1) that has a RunMacro action with a Repeat Count argument of 30,000.
  2. Create another macro (Macro2) that has a RunMacro action with a Repeat Count argument of 2.
  3. Instruct Macro2 to run Macro1.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access versions 1.0 and 1.1. This problem no longer occurs in Microsoft Access version 2.0.

MORE INFORMATION


If the Repeat Count argument falls between 0 and 32,767, Microsoft Access returns the expected results (no repeat).

If the Repeat Count argument falls between 32,767 and 65,535, Microsoft Access returns the error message listed above in the "Symptoms" section.

If the Repeat Count argument is greater than 65,535, Microsoft Access returns either the expected results (no repeat), the error message, or unexpected results.

Steps to Reproduce Behavior


  1. Open a blank, unbound form and save it as as Test Form.
  2. Create two macros (Increment by One and RepeatCount Test) as follows:

          Macro Name         Action
          ---------------------------
          Increment by One   SetValue
          RepeatCount Test Actions
          ------------------------
          SetValue
             Item: [field0]
             Expression: [field0]+1
          Macro Name         Action
          ---------------------------
          RepeatCount Test   RunMacro
                             MsgBox
          RepeatCount Test Actions
          ------------------------
          RunMacro
             Macro Name: Increment by One
             Repeat Count: 32767
          MsgBox
             Message: Done
  3. Add three controls to Test Form, as follows:

          Object: Text Box
          -----------------
          ControlName: Field0
             ControlSource: <leave blank>
          Object: Command Button
          ----------------------
          ControlName: Increment
             Caption: Increment
             OnPush: Increment by One
          Object: Command Button
          ----------------------
          ControlName: Repeat
             Caption: Repeat
             OnPush: RepeatCount Test
  4. Open Test Form in Form view. Type "1" in Field0, then choose Increment. Note that each time you choose Increment, the value in Field0 increases by 1.
  5. Type "1" in Field0, then choose Repeat. When the RepeatCount Test macro has run, the message "Done" is displayed. Note that the value in Field0 is now 32,767.

    To test different Repeat Count arguments, open the RepeatCount Test macro in Design view, change the Repeat Count argument, and repeat step 5.



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.

©1997 Microsoft Corporation. All rights reserved. Legal Notices.


Additional reference words: 1.00 1.10 macros RepeatCount ui
KBCategory: kbusage
KBSubcategory: McrActn