J
Jess
Hi,
I am trying to populate an exchange public folder with contacts, but I keep
getting COMExceptions ("The operation failed") after the 250th contact is
added. I have tried pausing the thread or waiting for the item added event to
fire, but still the exceptions keep flowing.
I have full access to the computer and the exchange server folder, and the
folder can hold more than 250 contacts if they are added manually.
The code I am using is:
Private Sub DoOutlookStuff()
Dim OutlookApp As Outlook.Application
Dim ns As Outlook.NameSpace
Const Folder As String = "GEMSContacts"
Const Server As String = "Server01"
Dim Coll As Outlook.Items
Dim fldr As Outlook.MAPIFolder
Dim a As Integer
'start outlook
Try
OutlookApp = New Outlook.Application
ns = OutlookApp.GetNamespace("Mapi")
Dim tempfldr As Outlook.MAPIFolder =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders)
fldr = tempfldr.Folders(Folder)
Coll = fldr.Items
Catch ex As Runtime.InteropServices.COMException
Stop
End Try
'delete all current contacts
While Coll.Count > 0
Try
Coll(Coll.Count).delete()
a += 1
Catch ex As Runtime.InteropServices.COMException
Stop
End Try
End While
Stop
'add contacts
Dim cn As Outlook.ContactItem
For a = 1 To 255
Try
cn = fldr.Items.Add
cn.FirstName = "Firstname"
cn.MiddleName = "Middlename"
cn.LastName = "Surname"
cn.Save()
Catch ex As Runtime.InteropServices.COMException
Stop 'this errors after 250 contacts are added
End Try
Next
End Sub
Any pointers as to why this is happening would be greatly appreciated.
Jess
I am trying to populate an exchange public folder with contacts, but I keep
getting COMExceptions ("The operation failed") after the 250th contact is
added. I have tried pausing the thread or waiting for the item added event to
fire, but still the exceptions keep flowing.
I have full access to the computer and the exchange server folder, and the
folder can hold more than 250 contacts if they are added manually.
The code I am using is:
Private Sub DoOutlookStuff()
Dim OutlookApp As Outlook.Application
Dim ns As Outlook.NameSpace
Const Folder As String = "GEMSContacts"
Const Server As String = "Server01"
Dim Coll As Outlook.Items
Dim fldr As Outlook.MAPIFolder
Dim a As Integer
'start outlook
Try
OutlookApp = New Outlook.Application
ns = OutlookApp.GetNamespace("Mapi")
Dim tempfldr As Outlook.MAPIFolder =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders)
fldr = tempfldr.Folders(Folder)
Coll = fldr.Items
Catch ex As Runtime.InteropServices.COMException
Stop
End Try
'delete all current contacts
While Coll.Count > 0
Try
Coll(Coll.Count).delete()
a += 1
Catch ex As Runtime.InteropServices.COMException
Stop
End Try
End While
Stop
'add contacts
Dim cn As Outlook.ContactItem
For a = 1 To 255
Try
cn = fldr.Items.Add
cn.FirstName = "Firstname"
cn.MiddleName = "Middlename"
cn.LastName = "Surname"
cn.Save()
Catch ex As Runtime.InteropServices.COMException
Stop 'this errors after 250 contacts are added
End Try
Next
End Sub
Any pointers as to why this is happening would be greatly appreciated.
Jess