I am writing some code to group users by a common manager in a Recordset. For example, userA and userB belong to Manager1, userC belongs to Manager2. This is being used in part to setup an email that will be sent to the Manager and CC'd to each of that Manager's users. This part works fine. However, in the email I am composing, I am trying to list each of these users in the body, where each user found is displayed on a new line (list form). I have tried using vbCrLf, vbNewLine, blank " ", but none of these are moving the next record found to a new line. Here is my entire code:
Code:
sqlStr = "SELECT DISTINCT tbl_activeAccts.[Manager] " & _
"FROM tbl_activeAccts;" 'query run to identify all managers
Set mgrRec = CurrentDb.OpenRecordset(sqlStr) 'managers query stored in a recordset for use later on
If (mgrRec.RecordCount = 0) Then
MsgBox ("No records found on tbl_activeAccts, import was empty or failed")
Exit Sub
Else
mgrRec.MoveLast
mgrRec.MoveFirst
Do While Not mgrRec.EOF
eTo = mgrRec.Fields("Manager") 'sets the TO field in the email equal to each manager from the earlier recordset
sqlStr = "SELECT tbl_activeAccts.[samAccountName], tbl_activeAccts.[Manager] " & _
"FROM tbl_activeAccts " & _
"WHERE (((tbl_activeAccts.[Manager])='" & mgrRec.Fields("Manager") & "') AND ((tbl_activeAccts.[pwdLastSet])<'" & "12345" & "'));"
Set secRec = CurrentDb.OpenRecordset(sqlStr) 'stores user data in a recordset
If (secRec.RecordCount = 0) Then
MsgBox ("No records found on tbl_activeAccts, import was empty or failed")
Exit Do
Else
secRec.MoveLast
secRec.MoveFirst
Do While Not secRec.EOF
eCC = secRec.Fields("samAccountName") & ";" & eCC 'CCs each managers' users so that each manager gets 1 email
userID = secRec.Fields("samAccountName") & " " & userID
secRec.MoveNext
Loop
CheckReturn = SendEmail(eSubject, eBody, userID, eBody2, eTo, eCC, Attachment1) 'sends the email based on the function below
eCC = "" 'sets the CC field to null value in order to avoid tagging every user on every email
End If
mgrRec.MoveNext 'cycles through for each manager in the recordset
Loop
End If
The piece in red is where I am having trouble. I structured it the same way as the eCC string above, but am trying to replace the ";" with the new line code.