Results 1 to 5 of 5
  1. #1
    pooldead is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    26

    Printing Each Record from a Recordset on a new line

    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.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    userID = secRec.Fields("samAccountName") & vbCrLf & userID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Oh, and if this is ending up in an HTML body maybe:

    userID = secRec.Fields("samAccountName") & "<BR>" & userID
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    pooldead is offline Novice
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    26
    pbaldy That did the trick! I had tried <BR> also, but I didn't put it in quotations.

    Thank you!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 19
    Last Post: 01-06-2018, 08:56 PM
  2. Validate one line in recordset?
    By Homegrownandy in forum Programming
    Replies: 7
    Last Post: 08-31-2017, 12:52 PM
  3. Replies: 20
    Last Post: 10-12-2015, 04:03 PM
  4. Replies: 4
    Last Post: 11-18-2013, 03:23 AM
  5. Replies: 7
    Last Post: 04-11-2011, 03:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums