lookforsmt
Registered User.
- Local time
- Today, 19:05
- Joined
- Dec 26, 2011
- Messages
- 672
Hi!
I have got the code from net, the code in the function which i call to send the email to multiple recipients and working well for my case.
The email body consists of summary report from the query in form of table.
I have three challenges:
1) The table created is right on top line without any line/space, so i am not able to open the email addressing to recipients, like:
Dear all,
Below is the summary snapshot for date _______
2) The email address is part of the code, instead of this i want the code to look into a table which has field stored email addresses and another field Yes or No. So if the row is ticked only then the email will be triggered to all those email address.
3) i want to add one more different summary snapshot along
Below is my code, can anyone help me to modify based on the above requirement.
I have got the code from net, the code in the function which i call to send the email to multiple recipients and working well for my case.
The email body consists of summary report from the query in form of table.
I have three challenges:
1) The table created is right on top line without any line/space, so i am not able to open the email addressing to recipients, like:
Dear all,
Below is the summary snapshot for date _______
2) The email address is part of the code, instead of this i want the code to look into a table which has field stored email addresses and another field Yes or No. So if the row is ticked only then the email will be triggered to all those email address.
3) i want to add one more different summary snapshot along
Below is my code, can anyone help me to modify based on the above requirement.
Code:
Public Function HtmlNoReportEmail(strTblQryName As String)
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim strMsg As String
Dim sqlString As String
Dim i As Integer
Dim rowColor As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
sqlString = "SELECT * From tbl_Summary"
rs.Open sqlString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strMsg = "<table border='1' cellpadding='3' cellspacing='3' style='border-collapse: collapse' bordercolor='#111111' width='800'>" & _
"<tr>" & _
"<td bgcolor='#7EA7CC'> <b>Entry_Date</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>VIP_flag</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>Deleted</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>Received</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>Rejected</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>Returned</b></td>" & _
"<td bgcolor='#7EA7CC'> <b>Total</b></td>" & _
"</tr>"
i = 0
Do While Not rs.EOF
If (i Mod 2 = 0) Then
rowColor = "<td align=center bgcolor='#FFFFFF'> "
Else
rowColor = "<td align=center bgcolor='#E1DFDF'> "
End If
strMsg = strMsg & "<tr>" & _
rowColor & rs.Fields("Entry_Date") & "</td>" & _
rowColor & rs.Fields("VIP_flag") & "</td>" & _
rowColor & rs.Fields("Deleted") & "</td>" & _
rowColor & rs.Fields("Received") & "</td>" & _
rowColor & rs.Fields("Rejected") & "</td>" & _
rowColor & rs.Fields("Returned") & "</td>" & _
rowColor & rs.Fields("Total") & "</td>" & _
"</tr>"
rs.MoveNext
i = i + 1
Loop
strMsg = strMsg & "</table>"
Set olApp = Outlook.Application
Set objMail = olApp.CreateItem(olMailItem)
With objMail
.BodyFormat = olFormatHTML
.HTMLBody = strMsg
.Recipients.Add "user1@email.com;user2@email.com"
.Subject = "Summary Report for date ____"
'.Send 'if you want to send it directly without displaying on screen
.Display 'if you want to display before sending
End With
Set olApp = Nothing
Set objMail = Nothing
End Function