Search code examples
loopsrecordsetms-access-2010mailing-list

creating a mailing list from recordset in access 2010 vba?


I'm trying to pull email addresses from a table and format them into a string that can be used in the "TO:" field of an outlook message. For some reason, the loop that i wrote is freezing the program. Can anyone spot what I'm doing wrong or offer a better way to do this? here is the code i have at the moment:

Private Function GetMailingList() As String

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim results As String

    results = ""
    Set db = CurrentDb
    Set rs = db.OpenRecordset("lut_holdEmailList")

        Do Until rs.EOF
            results = results & rs.Fields("emailAddress") & ", "

        Loop

    GetMailingList = results

End Function

Solution

  • You missed the MoveNext call:

    add this line to the Do Untill Loop

    rs.MoveNext()