• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Control Statements > 13.5. The Do Loop

The Do Loop

The Do loop has several variations. To describe these variations, we use the notation:

{While | Until}

to represent either the word While or the word Until, but not both. With this in mind, here are the possible syntaxes for the Do loop:

Do {While | Until} condition

   ' code block here

Loop

or:

Do

   ' code block here

Loop {While | Until} condition

Actually, there is a fifth possibility, because we can dispense with condition completely and write:

Do

   ' code block here

Loop

The Do loop is used quite often in DAO programming to iterate through a recordset. Here is a typical example that prints all values of a particular field in a recordset:

Sub DoExample(  )

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Objects")

rs.MoveFirst

Do While Not rs.EOF
   Debug.Print rs!Name
   rs.MoveNext
Loop

rs.Close

End Sub

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint