Link to home
Start Free TrialLog in
Avatar of padrepio2
padrepio2

asked on

DAO Recordset Loop

Hi
I'm attempting to loop through the values in a query (qryEmailRecipients) to establish if the value of a Yes/No field (Damage) is true.  If it is, then get the value of the 'emailaddress' field value.  Seems OK if all values of the Damage field are True but if one record has a False value, the code (I suspect) simply keeps looping.  Should I be testing for null?  

Set db = CurrentDb
Set rs = db.OpenRecordset("qryEmailRecipients")

Do While Not rs.EOF

If rs!damage = True Then
    strListEmail = strListEmail & ";" & rs!emailaddress
    rs.MoveNext
    
    Else
    End If
Loop


strListEmail = Mid(strListEmail, 2)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dale suggestion is the way to go, but if you want to know why your code is not working

-it is because the rs.MoveNext at line 8 is at the wrong location

- move the rs.MoveNext after  End If before Loop
Avatar of padrepio2
padrepio2

ASKER

Brilliant, thank you