Looping recordset

mark curtis

Registered User.
Local time
Today, 19:30
Joined
Oct 9, 2000
Messages
457
Dear all,

I am attempting to loop through a recordset and build a string of all email addresses where they have an associated report number in each record. But I am getting stuck in the loop?

Dim db As Database
Dim rs As Recordset
Dim intRptNo As Integer
Dim strEmail As String

Set db = CurrentDb
Set rs = db.OpenRecordset("tblDistList", dbOpenDynaset)

Do While Not rs.EOF
rs.MoveFirst
If rs!ReportNo = 1 Then strEmail = strEmail & "," & rs!Email 'rs.Fields("Email").Value
rs.MoveNext
Loop
MsgBox (strEmail)

Thanks
Mark
 
Your MoveFirst needs to be outside of your loop otherwise it will just keep returning to the first record.

rs.MoveFirst
Do While Not rs.EOF
 

Users who are viewing this thread

Back
Top Bottom