Do While Loop - it only updates 2 rows...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi~~

I have a main form with a sub form.
The following Do while loop only updates 2 rows, however, there are still 10
more records in the sub form.

Please look at this code. Thanks in advance... ^^

Do While rsTest.EOF = False
iTestFrequency = rsTest.Fields.Item("TestFrequencyNum")
'Find Limit
Do While rsLimit.EOF = False
If rsLimit.Fields.Item("Category") =
Val(Forms![frmTDS].Category.Value) _
And rsLimit.Fields.Item("LimitFrequencyFrom") <=
iTestFrequency _
And rsLimit.Fields.Item("LimitFrequencyTo") >=
iTestFrequency Then
With rsTest
rsTest.Fields.Item("Limit") = rsLimit.Fields.Item("Limit")
.Update
End With
Exit Do
Else
rsLimit.MoveNext
End If
Loop
rsTest.MoveNext
'Exit Do
Loop
 
submarine2000 said:
Hi~~

I have a main form with a sub form.
The following Do while loop only updates 2 rows, however, there are
still 10 more records in the sub form.

Please look at this code. Thanks in advance... ^^

Do While rsTest.EOF = False
iTestFrequency = rsTest.Fields.Item("TestFrequencyNum")
'Find Limit
Do While rsLimit.EOF = False
If rsLimit.Fields.Item("Category") =
Val(Forms![frmTDS].Category.Value) _
And rsLimit.Fields.Item("LimitFrequencyFrom") <=
iTestFrequency _
And rsLimit.Fields.Item("LimitFrequencyTo") >=
iTestFrequency Then
With rsTest
rsTest.Fields.Item("Limit") =
rsLimit.Fields.Item("Limit") .Update
End With
Exit Do
Else
rsLimit.MoveNext
End If
Loop
rsTest.MoveNext
'Exit Do
Loop

The code doesn't show how the recordsets were set or how they were
positioned before the loop, so that could be one problem. I see that
you aren't repositioning rsLimit at the first record before entering the
inner loop. Maybe you should insert this line:

If rsLimit.RecordCount > 0 Then rstLimit.MoveFirst

before the line:
 
I'm not sure you've shown enough of the code. The inner loop Do While
rsLimit.EOF = False is only to execute once, no matter how often the outer
loop Do While rsTest.EOF = False runs since you never reset rsLimit once you
reach the end the first time. Might that be the problem?
 
Back
Top