Question : Email Multiple Query Lines in the Body of an Email with Access

I need to send query results to specific individuals (The recipients will not change).  I need to send a query and would like multiple lines to appear in the email body.  I've attach some code that works but just returns the first line of the query.  Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Private Sub button_email_Click()
Dim db As Database
Dim rs As Recordset
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("qryEmail_IRs")
Recipient = "[email protected]"
With MailOutLook
        .To = Recipient
        .Subject = "Incident Report"
        .Body = rs!TripID & " " & rs!Booker
        .DeleteAfterSubmit = True
        .Send
    End With
    Set MailOutLook = Nothing
    Set appOutLook = Nothing
    Exit Sub

End Sub

Answer : Email Multiple Query Lines in the Body of an Email with Access

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
Private Sub button_email_Click() 
Dim db As Database 
Dim rs As Recordset 
Dim appOutLook As Outlook.Application 
Dim MailOutLook As Outlook.MailItem 
dim strBody as string
Set appOutLook = CreateObject("Outlook.Application") 
Set MailOutLook = appOutLook.CreateItem(olMailItem) 
Set db = CurrentDb 
Set rs = CurrentDb.OpenRecordset("qryEmail_IRs") 
rs.movefirst
do until rs.eof
   strBody=strBody & rs!TripID & " " & rs!Booker & vbcrlf
rs.movenext
loop
Recipient = "[email protected]" 
With MailOutLook 
        .To = Recipient 
        .Subject = "Incident Report" 
        .Body = strBody
        .DeleteAfterSubmit = True 
        .Send 
    End With 
    Set MailOutLook = Nothing 
    Set appOutLook = Nothing 
    Exit Sub 
 
End Sub 

Open in New WindowSelect All
Random Solutions  
 
programming4us programming4us