Unable to delete MAPI folder (MapiFolder.Delete)

J

jules

Hi.
I am a using Outlook 2000 on Windows XP and I am programming with VB6.
Currently I'm facing a strange problem with deleting a mapi folder
programmtically.
Situation: There are around 50 mapi folders (Fold01 - Folder48) that
have been created initially. Each of these folders does contain one!
subfolder. When Outlook starts, my COM-Adding should delete each
subfolder of each toplevel folder. This is done with
TopFolder.Subfolder.Delete. Subfolder of couse is of type MapiFolder.

This seems to work for the first 20 folders but when it comes to the
21st Outlook throws an error saying:
"Unable to delete this folder. Right-click the folder, and then click
Properties to check your permissions for the folder. See the folder
owner or your administrator to change your permissions."

According to this error message I've got some permission problem.
Unfortunately this not true because I did (more than once) randomize
the order in which each of the subfolders should be removed. Strangly
enough it is always the 21st folder that refuses to remove.
I did then try to remove these remaining folders manually. Same error
message here.
Does anybody ever faced a similar problem?
Any suggestions, hints, tips,....?

Thanx in advance and best regards
BB Hi.
I am a using Outlook 2000 on Windows XP and I am programming with VB6.
Currently I'm facing a strange problem with deleting a mapi folder
programmtically.
Situation: There are around 50 mapi folders (Fold01 - Folder48) that
have been created initially. Each of these folders does contain one!
subfolder. When Outlook starts, my COM-Adding should delete each
subfolder of each toplevel folder. This is done with
TopFolder.Subfolder.Delete. Subfolder of couse is of type MapiFolder.

This seems to work for the first 20 folders but when it comes to the
21st Outlook throws an error saying:
"Unable to delete this folder. Right-click the folder, and then click
Properties to check your permissions for the folder. See the folder
owner or your administrator to change your permissions."

According to this error message I've got some permission problem.
Unfortunately this not true because I did (more than once) randomize
the order in which each of the subfolders should be removed. Strangly
enough it is always the 21st folder that refuses to remove.
I did then try to remove these remaining folders manually. Same error
message here.
Does anybody ever faced a similar problem?
Any suggestions, hints, tips,....?

Thanx in advance and best regards
Jules
 
K

Ken Slovak - [MVP - Outlook]

You'd be best off posting questions like this to the outlook.program_vba
group, that's a place where programmers hang out.

You would need to show the code you're using. Are you using a down-counting
loop for the deletions?
 
J

jules

Hi.
OK here's a code snippet:

set WGFolders =
OutlooContext.MainFolder.AllWorkGroupFolder.WorkGroupFolders;
For i = 1 To WGFolders.Count
Set soWGFolder = WGFolders.Item(i)
If soWGFolder.WorkGroup.name = primaryWorkGroup Then

Set soWiFolder = soWGFolder
Call soWiFolder.SuspendFolder.Delete
'!!!!!!!!!!!!!!!!!!!!!!!!!!
End If

' .....
Next

Please keep in mind that this works with the first 20 MapiFolders and
the order does not seem to matter.

You see I'm using a up-counting loop but also tried with a for each
construct.
SuspendFolder is as I mentioned earlier the subfolder that should be
deleted and is of type MapiFolder!
Another strange thing is when I display that error message with
Err.Number I do always face a different error number.

P.S. I will also post my problem to outlook.program_vba

Best regards
Jules
 
K

Ken Slovak - [MVP - Outlook]

Never use an up-counting loop (For i = 1 to whatever or For Each) when
deleting or removing objects from a collection. Use a down-counting loop:

For i = colFolders.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