How to delete selective items from Sent Items from PF Script 
Author Message
 How to delete selective items from Sent Items from PF Script

I have a PF script from which I need to delete selective items from
the Sent Items folder. The following bit of code shows how I use a
filter to identify the messages I want from custom properties.

Set SntMsgs = myFolder.messages

SntMsgs.Filter=Nothing
Set oMsgFilter = SntMsgs.Filter
oMsgFilter.Fields.Add "EmployeeName", 8, StaffName
oMsgFilter.Fields.Add "StartDate", 7, dtStart
iMsgCount = SntMsgs.count

Call DebugAppend("Number of Items in Sent Items To "& StaffName & "
and StartDate of " &dtStart &" =" & SntMsgs.count,False)

If  iMsgCount > 0 Then
        For i = 1 to iMsgCount
                Call DebugAppend("Deleting Item" & i,False)
                SntMsgs.Item(1).Delete 1
        Next
Else
   Call DebugAppend("No Item Found",False)
End If

The DebugAppend statements write output to the log file and show that
I have a subset of the messages. However despite being in a loop the
Delete line only deletes the first item. If there are more than 1 item
matching the others are left.

Can anyone point out where I am going wrong. The requirement is to
delete all items that match the filter criteria.

Thanks,

Ross Ellard
Devonport Management Limited



Sat, 24 Apr 2004 22:09:06 GMT  
 How to delete selective items from Sent Items from PF Script
If you're deleting within a loop, you need to count down, not up, and delete
the ith item, not just item 1:

For i = iMsgCount to 1 Step -1
    SntMsgs.Item(i).Delete
Next

--
Sue Mosher, Outlook MVP
   Outlook and Exchange Solutions
   at http://www.slipstick.com


Quote:
> I have a PF script from which I need to delete selective items from
> the Sent Items folder. The following bit of code shows how I use a
> filter to identify the messages I want from custom properties.

> If  iMsgCount > 0 Then
>       For i = 1 to iMsgCount
> Call DebugAppend("Deleting Item" & i,False)
> SntMsgs.Item(1).Delete 1
> Next
> Else
>    Call DebugAppend("No Item Found",False)
> End If

> The DebugAppend statements write output to the log file and show that
> I have a subset of the messages. However despite being in a loop the
> Delete line only deletes the first item. If there are more than 1 item
> matching the others are left.

> Can anyone point out where I am going wrong. The requirement is to
> delete all items that match the filter criteria.



Mon, 26 Apr 2004 21:32:52 GMT  
 How to delete selective items from Sent Items from PF Script
Sue,
Thanks for the reply.

In the end it wasn't the For statement or the Delete Item. After some
more digging the For loop was not working at all as I had not Declared
the Loop variable i and had Option Explicit in the routine. The script
was not generating any error telling me 'i' had not been defined but
simply falling over.

Having declared i locally in routine everything started working as
expected.

Thanks for the suggestion anyway,

Ross

Quote:

> If you're deleting within a loop, you need to count down, not up, and delete
> the ith item, not just item 1:

> For i = iMsgCount to 1 Step -1
>     SntMsgs.Item(i).Delete
> Next

> --
> Sue Mosher, Outlook MVP
>    Outlook and Exchange Solutions
>    at http://www.slipstick.com



> > I have a PF script from which I need to delete selective items from
> > the Sent Items folder. The following bit of code shows how I use a
> > filter to identify the messages I want from custom properties.

> > If  iMsgCount > 0 Then
> >       For i = 1 to iMsgCount
> > Call DebugAppend("Deleting Item" & i,False)
> > SntMsgs.Item(1).Delete 1
> > Next
> > Else
> >    Call DebugAppend("No Item Found",False)
> > End If



Fri, 30 Apr 2004 19:31:53 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Programmatically delete an item from the Sent items

2. Programmatically delete an item from the Sent Items Folder

3. Delete a Sent Mail from the Sent Item

4. Hyperlink to PF item in email

5. Detecting an item move to Deleted Items folder

6. deleting an item or item set from a database

7. Howto trap MAPIFolder.Items.ItemAdd on Sent Items Folder

8. Meeting item when sent as item gives problems

9. Removal of attachments on email items in Sent items folder

10. deleted unread items script - interesting behavior

11. Deleting MailItems from the Sent Items folder

12. automate delete attachment in sent items?

 

 
Powered by phpBB® Forum Software