Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

There are a number of looping structures in VBA.  Here is a quick cheat sheet:

Loop Types:
For <var> = <start> To <end> (Step <amount to add>) / Next <var>

For Each <itm> In <array / collection> / Next <itm>

Do While <condition> / Loop
Do Until <condition> / Loop
Do / Loop While <condition>
Do / Loop Until <condition>
While <condition> / Wend
Do / Loop (use with caution. This is an infinite loop and you must use Exit Do somewhere in the body to get out of it)

Breaking out of loops:
Exit For
Exit Do
Note: you can’t break out of a While Wend loop with a keyword, but you can Goto a label to get out of it before the condition is met.

Continuing to the next loop iteration:
Note: There are no keywords to immediately skip to the next iteration, but you can add a Goto statement and put your label right before the end of your loop.  This will effectively skip all remaining instructions and move to the beginning of the next item in the loop.

Any questions?  Ask in a reply.