delteting contacts via vb

R

Roland Bialas

Hi NG,
i m on a little tool that collects contact data from an access DB. This
function works.

No i need to eraese all contacts wich might be entered with this tool. So i
set a flag in "categories" like "ACENTRY".

so my prog should look at every contact to determine if this is a user input
or the item was inserted by the prog.
If so it should be deleted.

but until now only few and random datas are deleted.
In the for each there is somewhere an error.
But i get no more information about it than 0.
Thanks
Roland

###### snipp #####
Public Function DelContacts()
On Error GoTo err_handler

Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim colContacts As Items
Dim objItem As Object
Dim strAddress As String


Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)
If Not objFolder Is Nothing Then
Set colContacts = objFolder.Items
For Each objItem In colContacts
If objItem.Categories = "RBENTRY" Then
objItem.Delete
End If
Next
End If
Set objItem = Nothing
Set colContacts = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
err_handler:
MsgBox Err.Description & Err.Number & Err.Source
'after a few successfull for echch the msgbox popsup with one single 0
exit function
End Function

###### snipp #####
 
K

Ken Slovak - [MVP - Outlook]

Deletions from a collection should always use a count down loop.
Otherwise the loop counter gets confused since you are changing its
parameters within the loop:
For i = colContacts.Count to 1 Step -1
 

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