Not able to display all record in email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neha2604
    New Member
    • May 2014
    • 1

    Not able to display all record in email

    I am using the below code to display all the record based on a condition, but it is displaying the last record.

    Code:
                   Dim objOutlook As Outlook.Application
                   Dim objOutlookMsg As Outlook.MailItem
                   Dim objOutlookRecip As Outlook.Recipient
                   Dim objOutlookAttach As Outlook.Attachment
                   Dim PLT As New ADODB.Connection
                   Dim MyRecSet As New ADODB.Recordset
    
                   Set PLT = New ADODB.Connection
                   PLT.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\ActionItem.mdb;"
                   PLT.Open
                   Set MyRecSet.ActiveConnection = PLT
                   MyRecSet.CursorLocation = adUseClient
                   MyRecSet.Open ("SELECT New_Action_Item,Assignee,Status,Description,Start_Date,End_Date,Action_ID FROM Action_item where status = 'open' ")
    Set objMessage = CreateObject("CDO.Message")
    
              ' Create the Outlook session.
              Set objOutlook = CreateObject("Outlook.Application")
    
              ' Create the message.
              Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
              With objOutlookMsg
                  ' Add the To recipient(s) to the message.
                  Set objOutlookRecip = .Recipients.Add("xyz.com")
                  objOutlookRecip.Type = olTo
    
                 ' Set the Subject, Body, and Importance of the message.
                 .Subject = "Action Item From Team Meeting"
                Do While Not MyRecSet.EOF
    
                 .Body = objMessage.TextBody & MyRecSet(0) & "     " & MyRecSet(1) & "    " & MyRecSet(2) & "   " & MyRecSet(3) & "   " & MyRecSet(4) & "    " & MyRecSet(5) & "     " & MyRecSet(6)
                 
                MyRecSet.MoveNext
                Loop
    
                 ' Resolve each Recipient's name.
                 For Each objOutlookRecip In .Recipients
                     objOutlookRecip.Resolve
                 Next
    
                 ' Should we display the message before sending?
                 
                     '.Save
                     .Send
               
              End With
              Set objOutlook = Nothing
    Last edited by Rabbit; May 14 '14, 03:31 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That's because you keep overwriting the Body of your email instead of appending to it. And for some reason you're using 2 different message objects.

    Comment

    Working...