end looping

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

Guest

I have a while loop which loops through a recordset.

How do I end the loop if a certain condition is met.

I have this code in the loop

If Diagnosis = rs.Fields.Item("DX") Then Me!approved = "YES"
If Diagnosis = rs.Fields.Item("DX") Then (what goes here to end the while
loop)

I realize I should be using a find statement instead of a loop but I have
not been able to get the syntax correct. I need this work asap and will work
on correcting the code.
 
Stefan said:
I have a while loop which loops through a recordset.

How do I end the loop if a certain condition is met.

I have this code in the loop

If Diagnosis = rs.Fields.Item("DX") Then Me!approved = "YES"
If Diagnosis = rs.Fields.Item("DX") Then (what goes here to end the while
loop)

I realize I should be using a find statement instead of a loop but I have
not been able to get the syntax correct. I need this work asap and will
work
on correcting the code.

If you're using Do While
then use Exit Do to get out of the loop.

Tom Lake
 
the syntax of a While...Wend statement is
While <condition>
' do something
Wend

i'm not sure how your posted code fits in that syntax. what condition are
you testing to run the loop?
you might find it easier to control the action using a Do...Loop statement,
where you can use an explicit Exit Do to get out of the loop at a
predetermined point. suggest you read up on both statements in Access VBA
Help, to help you decide which to use and how best to use it.

hth
 
Use a WHILE...WEND Statement as in...

While NOT rs.EOF
Wend

or

While (flgRecordFound = False AND NOT rs.EOF)
Wend

A word of caution though, from personal experience, I have NEVER buildt
a While...Wend using a conditional such as example #2 without problems -
my brain just doesn't get it. So I would put in a STOP statement
immediately before the loop starts and then step through the code using F8.
 
Back
Top