Richard: I am trying to send an email to multiple recipients without having to create a new form; it is just based off a button click. ie-email ADMIN. Then sending an email to all in the ADMINEmail Recordset. But only the last record in the recordset is showing up in the To: field when Outlook opens. Any help appreciated. Code as follows:
Dim OObj As Outlook.Application Dim OMsg As Outlook.MailItem Dim db As Database Dim rs As Recordset Dim EmailAddress As String Set OObj = CreateObject "Outlook.Application") Set OMsg = OObj.CreateItem(olMailItem) Set db = CurrentDb Set rs = db.OpenRecordset("65_EmailGroupADMIN_T") With rs
If .EOF And .BOF Then MsgBox "No emails will be sent becuase there are no records assigned from the list", vbInformation Else Do Until .EOF EmailAddress = ![Email] .Edit .Update OMsg.To = EmailAddress .MoveNext Loop OMsg.Display End If End With
rs.Close db.Close Set rs = Nothing Set db = Nothing Set OMsg = Nothing Set OObj = Nothing End Sub
Reply from Alex Hedley:
You have the lineOMsg.To = EmailAddress So To will always contain the last email address in your loop You will need to build up a string of emails in your loop instead
Dim strEmails strEmails = strEmails & EmailAddress & ";"
Then set the .To to your list OMsg.To = strEmails
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.