atticus1802
Registered User.
- Local time
- Today, 03:41
- Joined
- May 5, 2010
- Messages
- 43
Good Evening,
I have been trying to get this work for days. I have tried various pieces of code but this is the closest I can get to it working. I have a piece of code which populates an email with values from a datasheet. The datasheet contains multiple records however when the code is run I am shown only the record which has focus. This is populated for how many rows there are in a data sheet. I.e. 3 rows show 3 of the same emails.
Any help you can give would be greatly appreciated.
I have been trying to get this work for days. I have tried various pieces of code but this is the closest I can get to it working. I have a piece of code which populates an email with values from a datasheet. The datasheet contains multiple records however when the code is run I am shown only the record which has focus. This is populated for how many rows there are in a data sheet. I.e. 3 rows show 3 of the same emails.
Any help you can give would be greatly appreciated.
Code:
Private Sub cmd_sendmail_Click()
'Create mail merge
Set objOL = CreateObject("Outlook.Application")
Dim olApp As Object
Dim Address As String
Dim CCAddress As String
Dim Body As String
Dim rs As dao.Recordset
Forms!frmClearwell_Access_Entry!frmDatasheet.SetFocus
With Forms!frmClearwell_Access_Entry
Set rs = frmDatasheet.Form.RecordsetClone
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
Address = frmDatasheet!txt_Email_Address
CCAddress = frmDatasheet!txt_primemail + "; " + frmDatasheet!txt_secondemail
Body = "<p style='font-family:Calibri (Body);font-size:16'>" & "Dear " & frmDatasheet!txt_shortname & ", <br><br> Please find below your login details for the document review platform. <br><br > You can access it at the following link: <a href= 'https://l" & frmDatasheet!txt_CW_Box & "..com/esa'> [URL="https://clearwell"]https://[/URL]" & frmDatasheet!txt_CW_Box & "..com/esa</a>" & _
"<br><br> Your login details are as follows:- <br><br> Username: " & frmDatasheet!txt_User_ID & "<br> Password: " & frmDatasheet!txt_Password & _
"<br><br> I would recommend copying and pasting your password the first time you attempt to log in. <br><br> Please change this password as soon as possible, by clicking on the shown link:" & "<br><br> <img src='cid:CWpassword.jpg' height=100 width=210>" & "<br><br> If you have any queries, please email myself or " & frmDatasheet!com_Secondarycontact & " at <a href='mailto:" & frmDatasheet!txt_secondemail & "'>" & frmDatasheet!txt_secondemail & "</a>" & "<br><br> Kind Regards, <br><br>" & frmDatasheet!txt_primshortname & _
"<span style='Arial;font-size:13pt;color:rgb(128,128,128)'>" & "<br><b>___________________________________________________________</b><br>"</p>"
With rs
rs.MoveFirst
Do While Not rs.EOF
Set objMail = objOL.CreateItem(olMailItem)
objMail.Attachments.Add "P:\Project Database\Backend Database\Mail_Merge\CWpassword.jpg"
objMail.To = Address
objMail.CC = CCAddress
objMail.BodyFormat = olFormatHTML
objMail.Subject = "Login Details"
objMail.HTMLBody = Body
objMail.Display
rs.MoveNext
Loop
End With
rs.Close
Set olApp = Nothing
Set objMail = Nothing
End With
End Sub