Hi everybody!
I had an issue: I wanted to send personalized e-mails to a group of people indicating how much money they had to refund to my company.
I have a table which includes First Name, E-mail, Manager and Amount to reufund.
I have managed to create a code which send an e-mail to this persons and the body with the message personalized, however, it sends the mail to each people but does not matchs name with e-mail and the amount to refunds. It appears always the first name and amount that is on the table.
Do you have any idea on can I do to match this information? I have read in internet that I should do a looping to indicate to go to the next line.
Here's my code:
I had an issue: I wanted to send personalized e-mails to a group of people indicating how much money they had to refund to my company.
I have a table which includes First Name, E-mail, Manager and Amount to reufund.
I have managed to create a code which send an e-mail to this persons and the body with the message personalized, however, it sends the mail to each people but does not matchs name with e-mail and the amount to refunds. It appears always the first name and amount that is on the table.
Do you have any idea on can I do to match this information? I have read in internet that I should do a looping to indicate to go to the next line.
Here's my code:
Code:
Private Sub Command41_Click()
Dim MyDB As Database
Dim MyRS As Recordset
Dim MyTable As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Dim TheBody As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("Sheet2")
MyRS.MoveNext
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-mail message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = [Enterprise]
TheBody = "Dear " & [First] & "," & vbNewLine & vbNewLine & _
"You have to refund " & [Debe] & " to the company. Please review your situation." & vbNewLine & vbNewLine & _
"Greetings"
With objOutlookMsg
' Add the To recipients to the e-mail message.
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olBCC
' Set the Subject, the Body, and the Importance of the e-mail message.
.Subject = "Action Required: Please review assignment and/or MyTimeandExpenses information"
.Body = TheBody
.Importance = olImportanceHigh 'High importance
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With
MyRS.MoveNext
Loop
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set MyTable = Nothing
End Sub