Function test()
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 [LRM-Q2W]"
rs.Open sqlString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
i = 1
Dim rsChild As ADODB.Recordset
Do While Not rs.EOF
sqlString = "SELECT * FROM [LRMS-Q] Where LRMRID = " & rs!LRMRID
Set rsChild = New ADODB.Recordset
rsChild.Open sqlString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strMsg = strNsg & "<table border='1' cellpadding='1' cellspacing='1' style='border-collapse: collapse' bordercolor='#111111' width='800'>" & _
"<tr>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Delivery Date</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>PO No.</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Supplier</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Category</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Part Code</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Description</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Total Qty</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Unit</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Trips</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Qty/Trip</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Location</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Remarks</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Received Qty</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Completion %</b></font></td>" & _
"</tr>"
If (i Mod 2 = 0) Then
rowColor = "<td bgcolor='#FFFFFF'> "
Else
rowColor = "<td bgcolor='#E1DFDF'> "
End If
strMsg = strMsg & "<tr>" & _
rowColor & "<font size='2'>" & rs.Fields("DelDAte") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("PONo") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("Supplier") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("ItemCat") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("Item") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("Remarks") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("TMT") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("ItemUnit") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("Trips") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("MTPT") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("Loc") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("LRMRem") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("SumOfRMTx") & "</font></td>" & _
rowColor & "<font size='2'>" & rs.Fields("PCP") & "</font></td>" & _
"</tr></table>"
i = i + 1
strMsg = strNsg & "<table border='1' cellpadding='1' cellspacing='1' style='border-collapse: collapse' bordercolor='#111111' width='800'>" & _
"<tr>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Delivery Date</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Delivery Time</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>RMT</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Location</b></font></td>" & _
"<td bgcolor='#7EA7CC'> <font size='2'><b>Remarks</b></font></td>" & _
"</tr>"
Do While Not rsChild.EOF
If (i Mod 2 = 0) Then
rowColor = "<td bgcolor='#FFFFFF'> "
Else
rowColor = "<td bgcolor='#E1DFDF'> "
End If
strMsg = strMsg & "<tr>" & _
rowColor & "<font size='2'>" & Format(rsChild.Fields("Deldate"), "dd/MM/YY") & "</font></td>" & _
rowColor & "<font size='2'>" & Format(rsChild.Fields("Deltime"), "short time") & "</font></td>" & _
rowColor & "<font size='2'>" & Format(rsChild.Fields("RMT"), "0.00") & "</font></td>" & _
rowColor & "<font size='2'>" & rsChild.Fields("Rloc") & "</font></td>" & _
rowColor & "<font size='2'>" & rsChild.Fields("LRMSRem") & "</font></td>" & _
"</tr>"
i = i + 1
rsChild.MoveNext
Loop
strMsg = strMsg & </table><br>"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Dim objMessage, objConfig, Flds
Set objMessage = CreateObject("cdo.message")
Set objConfig = CreateObject("cdo.configuration")
Set Flds = objConfig.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.x.com"
Flds.Update
Set objMessage.Configuration = objConfig
objMessage.TO = "mat@x.com"
objMessage.FROM = "test<donotreply@x.com>"
objMessage.Subject = "Test Report For " & Format(Date - 2, "medium date")
objMessage.Fields.Update
objMessage.HTMLBody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & "3" & Chr(34) & ">" & "Good day," & "<br /><br />" & "Here are the daily test report for " & _
"<b>" & Format(Date - 2, "medium date") & "</b>" & "<br /><br /><b><u>" & "Test report" & "</b><br /></b></u>" & strMsg & _
"<br /><br />" & "Thank You," & "<br />" & "The X Team" & "</font>"
objMessage.Send
End Function