ACC2000: How to Create Do While and Do Until Loops in a MacroID: Q209790
|
To 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.
There are several types of Do loops. Each type handles the looping procedure and conditions differently. The different types of Do loops are as follows:
Macro Name Action
-------------------------
Do_Loop1 RunMacro
Loop1 MsgBox
Do_Loop1 Actions
--------------------------------------
RunMacro
Macro Name: Do_Loops.Loop1
Repeat Expression: <your_condition>
Loop1 Actions
-------------------
MsgBox
Message: ="Loop"
In this example, the Do_Loop1 macro calls the Loop1 macro while the
Repeat Expression parameter of the RunMacro action is true.
Macro Name Action
-------------------------
Do_Loop1 RunMacro
RunMacro
Loop1 MsgBox
Do_Loop1 Actions
--------------------------------------
RunMacro
Macro Name: Do_Loops.Loop1
RunMacro
Macro Name: Do_Loops.Loop1
Repeat Expression: <your_condition>
Loop1 Actions
-------------------
MsgBox
Message: ="Loop"
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.
Forms![CounterForm]![Counter]<=10If the condition is based on the value returned from a Visual Basic function, it will have syntax similar to:
-or-
Forms![EntryForm]![InvoiceNo].Visible=True
Time()>=TimeEntry()
Additional query words:
Keywords : kbusage kbdta McrCond
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: May 13, 1999