Why only half of the messages?? 
Author Message
 Why only half of the messages??

When I run the script below, why does it only run through half of the
messages rather than the whole bunch?  If I remove the DELETE
notation, it works on all messages.  I have to run this 5 times on a
folder full of messages until they're all done.

Anyone have any ideas?  I'm running Microsoft Outlook 2000 SR-1 w/
Microsoft Visual Basic 6.3

---start---
Sub ReportSave()
    Dim oApp As Application
    Dim oNS As NameSpace
    Dim oMsg As Object
    Dim oAttachments As Outlook.Attachments
    Dim strControl
    Dim myString

    Set oApp = New Outlook.Application
    Set oNS = oApp.GetNamespace("MAPI")
    Set myFolder = oNS.GetDefaultFolder(olFolderInbox)
    Set oFolder = myFolder.Folders("Change Memos")
    strControl = 0

    For Each oMsg In oFolder.Items
        With oMsg
                myString = Replace(oMsg, "/", "-")
                oMsg.Attachments.Item(1).SaveAsFile "C:\reports\in\"
                   & myString & ".rtf"
               .Delete
         End With
    Next
End Sub
---stop---

Thanks for any help.

Joe C.



Thu, 19 May 2005 03:39:54 GMT  
 Why only half of the messages??
You're seeing that behavior because of the way looping works when you're
deleting items.  I typically see this behavior when using a For i - 1 to
Items.Count loops however.

Try using
while oFolder.Items.Count > 0

'Code

wend

--
Patricia Cardoza
Outlook MVP
www.cardozasolutions.com

~Please post all replies to the newsgroup~

Quote:
> When I run the script below, why does it only run through half of the
> messages rather than the whole bunch?  If I remove the DELETE
> notation, it works on all messages.  I have to run this 5 times on a
> folder full of messages until they're all done.

> Anyone have any ideas?  I'm running Microsoft Outlook 2000 SR-1 w/
> Microsoft Visual Basic 6.3

> ---start---
> Sub ReportSave()
>     Dim oApp As Application
>     Dim oNS As NameSpace
>     Dim oMsg As Object
>     Dim oAttachments As Outlook.Attachments
>     Dim strControl
>     Dim myString

>     Set oApp = New Outlook.Application
>     Set oNS = oApp.GetNamespace("MAPI")
>     Set myFolder = oNS.GetDefaultFolder(olFolderInbox)
>     Set oFolder = myFolder.Folders("Change Memos")
>     strControl = 0

>     For Each oMsg In oFolder.Items
>         With oMsg
>                 myString = Replace(oMsg, "/", "-")
>                 oMsg.Attachments.Item(1).SaveAsFile "C:\reports\in\"
>                    & myString & ".rtf"
>                .Delete
>          End With
>     Next
> End Sub
> ---stop---

> Thanks for any help.

> Joe C.



Fri, 20 May 2005 01:41:57 GMT  
 Why only half of the messages??
Patricia, that was exactly what I needed for it to work!!!!  I simply
put that while/wend piece around my for-each/next loop.  Now it runs
the whole way through.

I tried doing something with "for count = " something or other (based
on another post) but I kept getting defining errors.

Thanks for the help!!!  :)

Joe Christl


Quote:
> You're seeing that behavior because of the way looping works when you're
> deleting items.  I typically see this behavior when using a For i - 1 to
> Items.Count loops however.

> Try using
> while oFolder.Items.Count > 0

> 'Code

> wend

> --
> Patricia Cardoza



Tue, 24 May 2005 19:59:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Formatted fields are half bold and half not bold

2. Telephone Message Pad...Half baked Idea I got..

3. looks like over half the messages in this forum never get an answer)

4. Why does Message Box does not display complete Message

5. why why why why

6. Why why why why?

7. Why is this Message Poping Up?

8. Why do I get this ERROR message????

9. VBA-what is it and why did I get this message

10. Why am I getting this message?

11. Help, why two messages?

12. Why can't I retrieve messages anymore?

 

 
Powered by phpBB® Forum Software