I am trying to download the attachments that I have in a folder in Outlook with the code :
If I declare dim atmt as attachment, the code does not even enter the loop that starts with For Each atmt In item.Attachments
I do have the amongst other the references
Microsoft Outlook 15.0 object library
Microsoft Office 16.0 Object library
the variable objSearchFolder.Items.Count returs the correct amount of emails in the folder. Any thoughts on why the varia atmt returns empty
Thanks a lot
Code:
Dim db As dao.Database
Dim ns As Namespace
Dim Inbox As MAPIFolder
Dim filename As String
Dim i As Integer
Dim objSearchFolder As Outlook.MAPIFolder
Dim item As MailItem
Dim atmt
Dim strSQL As String
Dim rst As dao.Recordset
Set db = CurrentDb()
Set ns = GetNamespace("MAPI")
Set rst = db.OpenRecordset("tblDocs", dbOpenDynaset)
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set objSearchFolder = Inbox.Folders("docs")
i = 0
If objSearchFolder.Items.Count = 0 Then
MsgBox "Search Folder is Empty", vbInformation, "Nothing Found"
End If
For Each item In objSearchFolder.Items
For Each atmt In item.Attachments
filename = "C:\eu\docs\docsArq\" & atmt.filename
item.SaveAsFile filename
strSQL = "INSERT INTO tblDocs(docPath)" & _
"VALUES ('" & filename & "')"
DoCmd.RunSQL strSQL
' item.Delete
atmt.SaveAsFile filename
i = i + 1
Next atmt
Next item
Set objSearchFolder = Nothing
Set Inbox = Nothing
Set ns = Nothing
MsgBox ("Done !!")
If I declare dim atmt as attachment, the code does not even enter the loop that starts with For Each atmt In item.Attachments
I do have the amongst other the references
Microsoft Outlook 15.0 object library
Microsoft Office 16.0 Object library
the variable objSearchFolder.Items.Count returs the correct amount of emails in the folder. Any thoughts on why the varia atmt returns empty
Thanks a lot