According to the thread "For...Next vs Do...Loop, and the Winner is?" you should use a For...Next loop if it has a fixed number of iterations and doesn't contain any logical conditions. This may be a dumb question but how do I know if my loop contains a fixed number of iterations? The majority of my loops consist of opening a recordset with a string expression equating to a query. Example:
or
The recordset type is always Snapshot. (If I do any updating/deleting I usually do a CurrentDb.Execu te "UPDATE..." , not on the recordset.) I want to loop through the recordset until EOF or until another condition is met if not at EOF. Here's an example of a For...Next loop that I have that illustrates this:
So, from what I described, which looping structure should I use?
Code:
strRstClass = "SELECT C.* FROM StdDegReqClass C INNER JOIN StdDegReqDisc D ON C.StdDegReqDiscId = " _
& "D.StdDegReqDiscId WHERE C.StdDegReqDiscId = " & lngDiscId & " ORDER BY C.SortOrder"
Set rstClass = CurrentDb.OpenRecordset(strRstClass, dbOpenSnapshot)
Code:
Set rstDegReqDisc = CurrentDb.OpenRecordset("SELECT * FROM DegReqDisc WHERE DegReqId = " & lngDegReqId, dbOpenSnapshot)
Code:
For intClass = 0 To rstClass.RecordCount
If rstClass.EOF Then
Exit For
End If
If sngDiscCredits >= rstDisc!CreditMin And lngDiscCourses >= rstDisc!CourseMin Then
lngTakenDiscId = lngDiscId
Exit For
End If
'more code....
rst.MoveNext
Next
Comment