• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 664
  • Last Modified:

Outlook 2007 Recipients.Add problem


A developer has created a job management database that interfaces with Outlook 2007 to eMail job tenders to contractors. Under Office 2003 it works fine, but under Office 2007 it fails.

The system has a valid and up-to-date anti-virus solution, and the programmer is using "late binding". Actual code being used is listed below, with the error occuring at the line:

"Set objOutlookRecip = objOutlookMsg.Recipients.Add(Address(i))"

We're stumped on this - any ideas would be very much appreciated.

Public Sub SendMailPlus(Address() As String, Subject As String, message As String, mailType As Integer, _
   importance As Integer, AttachmentPath() As String)
On Error GoTo Err
   Dim i As Integer
   ' Converted to late binding for compatibility between different versions of Outlook
   Dim objOutlook As Object         ' was Outlook.Application
   Dim objOutlookMsg As Object      ' was Outlook.MailItem
   Dim objOutlookRecip As Object    ' was Outlook.Recipient
   Dim objOutlookAttach As Object   ' was Outlook.Attachment
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(0)    ' was 0 = olMailItem
   ' Add BCC recipients
   For i = 1 To maxEmails
      If Len(Address(i)) > 0 Then
         Set objOutlookRecip = objOutlookMsg.Recipients.Add(Address(i))
         objOutlookRecip.Type = mailType
      End If
   Next i
   ' Message parameters
   objOutlookMsg.Subject = Subject
   objOutlookMsg.Body = message & vbCrLf & vbCrLf
   objOutlookMsg.importance = importance
   objOutlookMsg.ReadReceiptRequested = True
   ' Add primary attachment
   Set objOutlookAttach = objOutlookMsg.Attachments.Add(AttachmentPath(0))
   ' Add secondary attachments
   For i = 1 To maxFiles - 1
      If Len(AttachmentPath(i)) > 0 Then
         If FileExists(AttachmentPath(i)) Then
            Set objOutlookAttach = objOutlookMsg.Attachments.Add(AttachmentPath(i))
         End If
      End If
   Next i
   ' Send email
   ' Cleanup
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
   Exit Sub
   Call MsgBox("There was an error creating the email messages", vbCritical, kError)
End Sub

Open in new window

  • 3
  • 2
1 Solution
Patrick MatthewsCommented:
Hello The_Maverick,

When you say it fails, what is the exact error message?  You will need to turn off the error handler to get it...


The_MaverickAuthor Commented:
Sorry about the delay in getting back to you Patrick. I'll need to get the developer to talk me through turning off the error handler next time I'm on site - which will probably be Monday now.
Patrick MatthewsCommented:

That's easy--just comment out "On Error GoTo Err"



The_MaverickAuthor Commented:
"That's easy--just comment out "On Error GoTo Err""

Easy for you :)
The_MaverickAuthor Commented:
Hi Patrick (and others),

Problem solved by developer ...

The developer discovered that if Outlook 2007 is already running when the eMail is sent then it works properly, whereas if Outlook ISN'T already running it fails. According to the developer this is a Microsoft "feature" to prevent malware from sending eMails via outlook without the users knowledge.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now