Runtime error -1629224689

  • Thread starter Thread starter noone
  • Start date Start date
N

noone

Hello all,
The code below works fine with one message selected,
however, it crashes when multiple ones are selected with
the above runtime error.

The crash occurs between the ========= lines
But I think it is because of this line:
Set myForward = oExp.Selection.Item(1).Forward

Any ideas ?

Dim oExp As Outlook.Explorer
Set oExp = Outlook.ActiveExplorer
Set objSelection = oExp.Selection

If objSelection.Count > 0 Then
For Each objItem In objSelection
If TypeOf objItem Is MailItem Then
Set SafeItem = CreateObject("Redemption.SafeMailItem")
Set myForward = oExp.Selection.Item(1).Forward
SafeItem.Item = myForward
=======================================
With SafeItem
.Recipients.Add "#Unsolicited Email"
.Body = "Forwarded via Outlook Anti-Spam"
.DeleteAfterSubmit = True
.Send
End With
=======================================
objItem.Delete
End If
Next
End If
 
i think i fixed it, changed:
Set myForward = oExp.Selection.Item(1).Forward
to
Set myForward = objItem.Forward
 
Eek! You're deleting inside a For Each ... Next loop.
Don't do it! Instead use a loop that counts down from
Selection.Count to one and forwards and deletes the
current item in the loop, not the oExp.Selection.Item(1).
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
can you help ? i am completely new to this, this is my first attempt
and i was happy that it was even working ;)

i was getting all confused with this count and that count, loops, etc.
 
i had figured out how to do the forwarding, but now i'm not clear if my
for/next loop
is "correct". is there a better way to process the selections ? i guess
there is since i read
an "eek" in your reply ;)
 
A countdown loop would look like this:

intCount = objSelection.Count
For i = intCount to 1 Step -1
Set objItem = objSelection(i)
' do stuff with objItem
Next

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top