The information in this article applies to:
Moderate: Requires basic macro, coding, and interoperability skills. This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp). SUMMARYTo perform a Do While or Do Until loop in a Microsoft Access macro, you need to use a combination of correct macro structure and the RunMacro action with appropriate information supplied in the Repeat Expression parameter. These requirements are described in more detail later in this article. MORE INFORMATIONThere are several types of Do loops. Each type handles the looping procedure and conditions differently. The different types of Do loops are as follows:
Do While <Condition>... Loop and Do Until <Condition>... Loop
In this example, the Do_Loop1 macro calls the Loop1 macro while the
Repeat Expression parameter of the RunMacro action is true.
Do... Loop While <Condition> and Do... Loop Until <Condition>
In this example, the Do_Loop1 macro calls the Loop1 macro once
unconditionally, and then continues to call the Loop1 macro while the
Repeat Expression parameter of the RunMacro action is True.
ConditionsThe condition used in the loop, which is supplied in the Repeat Expression parameter of the RunMacro action, can be based on a value in a field on a form, a property of a control on a form, or the value returned from a Visual Basic function. If the condition is based on a field in a form or a property of a control on a form, it will have syntax similar to:Forms![CounterForm]![Counter]<=10If the condition is based on the value returned from a Visual Basic function, it will have syntax similar to:
Do While Loops vs. Do Until LoopsWhether a loop is a Do While loop or a Do Until loop depends on the condition. The RunMacro action runs the macro until the condition in the Repeat Expression parameter is false. This behavior is exactly what is needed for a Do While loop. It is, however, the opposite of what is needed for a Do Until loop. Therefore, to make a condition for a Do Until loop work correctly, precede the condition in the RunMacro action with the NOT operator.Additional query words:
Keywords : kbusage kbdta McrCond |
Last Reviewed: May 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |