Dear All,
I have the following code
Code:
Dim dbs As DAO.Database Dim strsql As String Dim rs As DAO.Recordset Set dbs = CurrentDb strsql = "qry_emailing_id" Set rs = CurrentDb.OpenRecordset(strsql) Do While Not rs.EOF CurrentDb.QueryDefs("qry_emailing").SQL = Replace(CurrentDb.QueryDefs("qry_emailingtemplate").SQL, "insert", rs!UserID) Dim rs2 As Recordset Set rs2 = CurrentDb.OpenRecordset("qry_emailing", dbOpenDynaset) With rs2 Do While Not .EOF mailbody = mailbody & !UserID & "|" & !Username & "|" & !HolidayDate & "|" & !Status & "|" & !StatusMan & "|" & !ManActionDate & vbCrLf .MoveNext Loop End With rs2.Close Set rs2 = Nothing DoCmd.SendObject acSendNoObject, , , rs!UserID, , , "SUBJECT", mailbody rs.MoveNext Loop rs.Close Set rs = Nothing
The intention here is to send emails to userIDs in qry_emailing_ID and each recipient would receive the relevant record in qry_emailing
Now if I run the code the first email is correct, first user gets his records, but in the second email everything is included, not only the records of the second userID
Could you please advise?
Many thanks in advance