Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete contacts in outlook

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I have a custom contacts folder in outlook I wish to update from a table.
I can add contacts, but just can't seem to delete contacts?
Anyone help?

code to add:
Code:
loNewContact = oDefaultfolder.Items.Add()

when I try this code I get an ole error "Parameter not optional"

Code:
	oItems=oDefaultFolder.items
	FOR EACH oItem IN oItems
		oItems.delete( )
	endfor
 
I see a couple of issues. First, the method for removing an item is Remove, not Delete.

Second is the issue you always have when deleting items from a collection; it's a moving target. Normally, you need to go backward through a collection to delete each member.

Code:
FOR nItem = oItems.Count TO 1 STEP -1
   oItems.Remove(m.nItem)
ENDFOR

The third is more subtle. I suspect that the oItems collection you create by grabbing oDefaultFolder.Items is a copy of the actual collection, not the original. I think you need to loop through the original. So try this:

Code:
FOR nItem = oDefaultFolder.Items.Count TO 1 STEP -1
   oDefaultFolder.Items.Remove(m.nItem)
ENDFOR

Tamar
 
Thanks Tamar,

I went straight to the second piece of code and it worked perfectly, thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top