×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Not all recipients added to Outlook MailItem

Not all recipients added to Outlook MailItem

Not all recipients added to Outlook MailItem

(OP)
I am using the following to try and add recipients to an Outlook MailItem:

CODE

Dim objApp As outlook.Application
Dim objMail As MailItem
Dim objBCC As outlook.Recipient

On Error GoTo Err_Mail

Set objApp = CreateObject("Outlook.application")
Set objMail = objApp.CreateItem(olMailItem)
Set objBCC = objMail.Recipients.Add(pubAuditorEmail)
For i = 1 To 5
  If Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(0) <> pubAuditor_i Then
    Set objBCC = objMail.Recipients.Add(Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(2))
  End If
Next i
objBCC.Type = olBCC
.... 

I find however, that objBCC then only contains the last recipient added in the For loop (all the addresses are valid). What am I doing wrong?

RE: Not all recipients added to Outlook MailItem

First it looks to me like you want objBCC to be a collection of recipients not a single recipient. Also inside the loop you keep resetting it. I think you want

CODE -->

Dim objApp As outlook.Application
Dim objMail As MailItem
Dim objBCC As outlook.Recipients
On Error GoTo Err_Mail
Set objApp = CreateObject("Outlook.application")
Set objMail = objApp.CreateItem(olMailItem)
Set ObjBcc = ObjApp.recipients
objBCC.Type = olBCC
objBCC.Recipients.Add(pubAuditorEmail)
For i = 1 To 5
  If Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(0) <> pubAuditor_i Then
    objBCC.Recipients.Add(Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(2))
  End If
Next i 

RE: Not all recipients added to Outlook MailItem

(OP)
Thank you, MajP, but this gives a Type mismatch error at the first 'Set objBCC...'. I have subsequently discovered that the solution seems to be to declare the type of each recipient immediately after adding it:

CODE

Dim objApp As Outlook.Application
Dim objMail As MailItem
Dim objBCC As Outlook.Recipient
On Error GoTo Err_Mail
Set objApp = CreateObject("Outlook.application")
Set objMail = objApp.CreateItem(olMailItem)
Set objBCC = objMail.Recipients.Add(pubAuditorEmail)
objBCC.Type = olBCC
For i = 1 To 5
If Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(0) <> pubAuditor_i Then
  Set objBCC = objMail.Recipients.Add(Me.Controls("Subform" & Format(i, "0"))!keuAuditor.Column(2))
  objBCC.Type = olBCC
End If
Next i
objMail.Subject = MijnSubject
... 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close