Issues with COMException

N

NateG

I created a program that scans a text file containing e-mail addresses and
distribution lists which were originally created in Eudora. It then parses
them and adds them into Outlook to populate someone's individual and DL
contacts. We deployed it in February and everything seemed to be working
fine. It's only been used about 10 times altogether without any error
messages. Now suddenly, we are getting a bizarre error message that I have
been able to find a solution to. It occurs when adding a DL and only occurs
seemingly random. Here's the snippet it's occuring in:

Private Sub addList(ByVal listName As String, ByVal memberList() As String,
ByVal memberEmails() As String)
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim oDL As Outlook.DistListItem
Dim i As Integer
Dim oRecipient As Outlook.Recipient

oApp = CreateObject("Outlook.Application")
oNS = oApp.GetNamespace("MAPI")
oDL = oApp.CreateItem(Outlook.OlItemType.olDistributionListItem)
oDL.DLName = listName
oDL.Save()

'Populate the DL with individual e-mails.
For i = 0 To UBound(memberEmails)
'MessageBox.Show(memberList(i) + " " + memberEmails(i))
If memberList(i) = Nothing Then
Exit For
End If
oRecipient = oNS.CreateRecipient(memberList(i) & "<" &
memberEmails(i) & ">")


**********************************
'Here is where I'm getting the error message when it tries to do the
oRecipient.Resolve() call. It give the following error message on the
debugger:

COMException unhandled by the user
The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
**********************************

oRecipient.Resolve()
oDL.AddMember(oRecipient)
oDL.Save()
Next

oDL.Save()

'Clean up
oApp = Nothing
oNS = Nothing
oDL = Nothing
oRecipient = Nothing
End Sub


Any thoughts?
 
K

Ken Slovak - [MVP - Outlook]

Have you run in debug mode to see if the recipient object is actually
created before you call Resolve on it?

Does this happen with all entries from your list or only some? If some then
look at the values being passed and make sure they are valid email
addresses.

You also should add try...catch blocks to handle any exceptions.

Also, Resolve is a function, try getting and checking the Boolean return
value when you call it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top