item.attachments(x).remove and .delete does not work

C

Carsten Lahme

Hi NGs,

again I run into a 'litle' problem.
We have a VBA-Script in Outlook, that works fine. Now we want to
migrate this to a DLL using VS .NET 2k3
This is the part, where an error occurs:

Counter = 1
On Error GoTo ErrHandler
While Counter - 1 < NumAttachments
If Item.Attachments(Counter).Type <> 6 Then
Item.Attachments(Counter).delete()
NumAttachments = Item.Attachments.Count
Else
Counter = Counter + 1
End If
End While

It should remove all attachments but type of OLE of a mail-item.
If there are only one or two attachments, it works fine. Three or more
run into an error if the last attachment should be removed.
I also tried to use the remove-methode. that one runs, but doesn't
remove the attachments, if the mail is send -very strange but found in
other threads, too.

Can anyone explain and maybe give a solution?

rgds

Carsten
 
S

Sue Mosher [MVP-Outlook]

Attachment.Remove is broken in some versions of Outlook. I'd stay away from
it. Try using a countdown loop:

For Counter = NumAttachments to 1 Step -1
att = Item.Attachments(Counter)
If att.Type <> 6 Then
att.Delete
End If
Next
Item.Save
 
C

Carsten Lahme

Hi Sue, Hi NG's.

Thanks for reply, but it doesn't seem to work.
I changed the script like this:

Counter = 1
On Error GoTo ErrHandler
While Counter - 1 < NumAttachments
MyAttachment = Item.attachments(Counter)
If MyAttachment.Type <> 6 Then
MyAttachment.delete()
NumAttachments = Item.Attachments.Count
Else
Counter = Counter + 1
End If
End While
Item.save()

When I run in debugmode it jumps to the ErrHandler if:
NumAttachments=1
in the line where it comes to the deletion of it (the last remaining
attachment)
The ErrHandler comes up with:

"Error # -2147221233 was generated by Microsoft Outlook Nicht genügend
Arbeitsspeicher oder Systemressourcen. Schließen Sie einige Fenster
oder Programme und versuchen Sie es erneut."

In english:
Not enough memory or systemresources. close some applications or
windows and try again.

The Message comes up if I run in debug or normal mode. I have no other
applications running. The System is 1GHz / 512MB Windows 2000 SP4
german with Outlook2000 (Office2k premium) german.
Dev-Version is Visual Studio .Net 2003 using Visual Basic.

Thanks again for any help with this. If You need more informations,
just ask.

rgds

carsten
 
C

Carsten Lahme

Hi Again,

in desserts sandstorms come with a sudden and disapear before You
brushed of the sand from Your eyes.
The same with this problem. all of a sudden it is gone.
I didn't change anything at the routine.
There where some problems with the references resulting the addin not
being loaded everytime outlook starts.
This problem is solved -more or less; and now the deleting routine
runs without error.

Why do my collegues from the Delphi-Dev-Team laugh at me?
Is it cause I'm using MS-Enviroment?

Very strange.....
 

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