Truncated file header

prasadgov

Member
Local time
Yesterday, 19:24
Joined
Oct 12, 2021
Messages
124
Hi,

I import XML attachments everyday from Outlook emails to an attachment folder in C. When I run the Rules in Outlook, which executes the Outlook macro to download the attachments, It comes in as Proc_ID_1111-Pam_WALT-11-18-24_13-41-15.

I mimicked the same code in Access button action and it imports with no issues but it downloads to the attachment folder as Proc 11-18-24 13-41-15.
The name, the ID and underscores are missing when imported through Access VBA.

This is my partial code
Code:
........
Set OlItems = MYFOLDER.Items
    
    For Each olMail In OlItems

        If olMail.subject Like "*Proceeding ID*" Then
            strFile = olMail & ".XML"
            strFile = strFolderpath & strFile
            If olMail.Attachments.Count > 0 Then
                    x = olMail.Attachments.Count
                    Do Until x = 0
                         strFile = strFolderpath & olMail.Attachments.Item(x)
                         olMail.Attachments.Item(x).SaveAsFile strFile
                         x = x - 1
                    Loop
               
                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


            End If
        End If
    Next
    Set olMail = Nothing
    Set olApp = Nothing

Any pointers?

TIA
 
You are overwriting strfile. :(
Walk your code.
hmm..I think this line is not needed

strFile = strFolderpath & olMail.Attachments.Item(x)

Instead should it be?
Code:
Do Until x = 0
                     
   olMail.Attachments.Item(x).SaveAsFile strFile
    x = x - 1
Loop
 
Last edited:

Users who are viewing this thread

Back
Top Bottom