Loop out of sync?

  • Thread starter Thread starter Peter J. Veger
  • Start date Start date
P

Peter J. Veger

I have a small loop to remove all items from a contacts subfolder, with Itms
set to the items of a subfolder of the default contacts folder, as follows

Do While Itms.Count > 0
Itms.Remove 1
Loop

When running with a breakpoint on the Do (removing one item in each step),
everything works correctly.
When letting the code run, with a breakpoint at the statement after Loop, I
get an error:
"The item could not be deleted. It was either moved etc."
 
Does it work if you either add a DoEvents statement after you delete
each item (slowing things down) or use a count down For loop
(preferable):

For i = Itms.Count To 1 Step -1
Itms.Remove i
Next i
 
Downcounting works.
Thanks,

Ken Slovak - said:
Does it work if you either add a DoEvents statement after you delete
each item (slowing things down) or use a count down For loop
(preferable):

For i = Itms.Count To 1 Step -1
Itms.Remove i
Next i
 
Back
Top