Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook attachments, where are they stored?

Status
Not open for further replies.

ToyFox

Programmer
Jan 24, 2009
161
US
I have linked to an outlook mailbox, it acts like a table.
If one of the records (emails) contains an attachment, there is a field named "Has Attachments" which contains -1 or 0.
My question is where and how can I get hold of the attacments.
The supervisor double clicks on the record (but if it has an attachment, the supervisor does not see it). Can anyone explain where the attachment is stored.
 
Attachments are part of the body of an email. I believe you will have to save to disk using automation. Here are some notes:

Code:
Sub GetOutlookAttachment()
'Reference: Microsoft Outlook x.x Library

Dim oAp As New Outlook.Application
Dim oInbox As MAPIFolder
Dim oItem As Outlook.MailItem
Dim oAttach As Outlook.Attachment
Dim strFilename
    
On Error GoTo ErrTrap

'Used as an example, each mail item has a unique ID
'You can use the entry ID as a parameter
strEntryID = "00000000181C74A235F20144848742C9CD279E4764072001"


Set oInbox = oAp.GetNamespace("MAPI").GetDefaultFolder(6) 'olFolderInbox=6
Set oItem = oAp.GetNamespace("MAPI").GetItemFromID(strEntryID)
'Set oItem = oInbox.Items.Find("[EntryID] = '" & strEntryID & "'")

If oItem.Attachments.Count > 0 Then
    For Each oAttach In oItem.Attachments
        strFilename = CurrentProject.Path & "\" & oAttach.FileName
        oAttach.SaveAsFile strFilename
        'This is not very sensisble if there are a lot of attachments
        FollowHyperlink strFilename
    Next
End If

Exit_Here:
'Clean up code here
Exit Sub

ErrTrap:

If Err.Number = -209452785 Then
    MsgBox "Item not found."
Else
    'Other error message
End If

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top