I have the following code, which works perfectly to send an email.
Code:
Private Sub Yes_Click()
On Error GoTo SendEmail_Err
Dim myOlApp As Object
Dim myNameSpace As Object
Dim myFolder As Object
Dim myItem As Object
Dim myAttachments, myRecipient As Object
Dim recipient As String
Dim file_name As String
Dim mySubject As Object
Dim dbs As Object
Dim rst As Object
Dim strSQL As String
strSQL = "EmailSendExpDate"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
rst.MoveFirst
While Not rst.EOF
recipient = rst![Business Email Address]
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
Set myRecipient = myItem.Recipients.Add(recipient)
'"Message Subject String Here"
myItem.Subject = "Upcoming Renewal/Expiration Date"
'"Put Message Body Text Here"
myItem.Body = 'enter the text here
myItem.Display
rst.Edit
rst!Emailed = True
rst!EmailedDate = Date
rst.Update
rst.MoveNext
Wend
DoCmd.Close acForm, "EmailSendNotification"
Set myRecipient = Nothing
Set myAttachments = Nothing
Set myItem = Nothing
Set myOlApp = Nothing
Set rst = Nothing
SendEmail_Exit:
Exit Sub
SendEmail_Err:
MsgBox Err.Description
Resume SendEmail_Exit
End Sub
My problem occurs when I go to add a CC to the email. I have tried the following:
Code:
Set myRecipient = myItem.Recipients.Add(recipient)
Set myRecipient = myItem.Recipients.Add("abc@123.com" & "; " & "abc@def.com")
myRecipient.Type = olCC
I have this exact code in a sample database and it adds the CC's perfectly but when I try it in the actual db it doesn't add the CC's at all. I don't get any errors, so I don't know why it's not working.
Is this the proper/most effective way to add a CC to my email? I found this solution at: http://msdn.microsoft.com/en-us/libr...ffice.11).aspx