Loop gets limited (1 Viewer)

prasadgov

New member
Local time
Today, 06:29
Joined
Oct 12, 2021
Messages
16
two things..
it still stopped import after the 16th item, when there was 17 in total.
Also, it throws an error at .Name
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:29
Joined
Sep 21, 2011
Messages
14,301
Well you need to look at what you could use to give a different filename each time.
If it is early bound. You can step through the properties with intellisense.

Again, walk your code. :(
 
Last edited:

prasadgov

New member
Local time
Today, 06:29
Joined
Oct 12, 2021
Messages
16
This morning there was only one item so I was unable to recreate the error. But this is my code, which stopped after the 16th item yesterday.
Code:
Set OlItems = MYFOLDER.Items
    
    'For Each olMail In OlItems
        y = olMail.Count
        Do Until y = 0
            If olMail.subject Like "*Proceeding ID*" Then
                strFile = olMail & ".XML"
                strFile = strFolderpath & strFile
                If olMail.Attachments.Count > 0 Then
                    'For x = 1 To olMail.Attachments.Count
                        x = olMail.Attachments.Count
                        Do Until x = 0
                            'olMail.Attachments.Item(x).SaveAsFile strFile
                             strFile = strFolderpath & olMail.Attachments.Item(x).Name
                             olMail.Attachments.Item(x).SaveAsFile strFile
                             x = x - 1
                        Loop
                    'Next x
                    
                    subject = olMail.subject
                    sreplace = "_"
                    subject = Replace(subject, " ", sreplace)
                    olMail.Body = olMail.Body & vbCrLf & "The file was processed " & Now()
                    olMail.subject = "Processed - " & subject
                    olMail.Move objDestfolder
                    'olMail.Save
    
                End If
            End If
            y = y - 1
        Loop
    'Next
 
    Set olMail = Nothing
    Set olApp = Nothing
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:29
Joined
Feb 19, 2002
Messages
43,275
If it processed 1 then it processed the first and the last. Send yourself three emails. Open the code and step through it as each email is processed so you find the problem.
 

Users who are viewing this thread

Top Bottom