Solved

Grab info with Attachments from Outlook to Access table

Posted on 2014-03-13
4
264 Views
Last Modified: 2014-04-01
I am trying to grab Email info and put it into an access table. I have 99 percent of it working except for how to do attachments. I tried researching it but it tends to be very vague in how to do it. Here is the code I have now that is working just fine. What i'm looking for is the code to add to grab attachments and place them into the table to read. I do have a field in the table called attachment and it is defined as an attachment field.

Dim TempRst As DAO.Recordset
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
 
Set db = CurrentDb
 
Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
 
Set InboxItems = Inbox.Items
 
For Each Mailobject In InboxItems
    If Mailobject.UnRead Then
    With TempRst
        .AddNew
        !Subject = Mailobject.Subject
        !From = Mailobject.SenderName
        !To = Mailobject.To
        !Body = Mailobject.Body
        !DateSent = Mailobject.SentOn
        !Attachment = ???????????????
        .Update
        Mailobject.UnRead = False
 
    End With
End If
Next
 
Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
0
Comment
Question by:Grizbear51
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39928101
I don't think there is any way to copy an email attachment to an Attachment field.  You will need to save each attachment to a temporary file using the Attachment.SaveAsFile method, then load it into Access using the Field2.LoadFromFile method, then delete the temporary file.

The documentation on these two methods is here:
http://msdn.microsoft.com/en-us/library/office/ff869359.aspx
http://msdn.microsoft.com/en-us/library/office/ff197396.aspx

There are examples of their use on those pages.  Note that to access the methods and properties associated with attachments and multi-value fields, you must declare your objects as Recordset2 and Field2.

-- Graham Mandeno [Access MVP 1996-2014]
0
 
LVL 75
ID: 39928113
Graham ... instead of using the Attachment field, could we load into a OLE Object Unbound field instead ?

mx
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 39928287
Hi Joe

I think an Attachment is much more flexible in terms of the file formats it will support, and also its data compression capability.  Besides, it's what Grizbear51 says s/he is using.

Personally, I would not store the attachments in the database at all, but extract them into a subfolder and have the database reference them by file path.

Cheers,
Graham
0
 
LVL 75
ID: 39969901
"I would not store the attachments in the database at all"
Well, the reason I asked this question is .... it's related to the post I made in Arvin's DL ... where the subject was "test' ... when I mentioned I was build a Web App - grabbing Outlook data, which ultimately would end up in SQL ASURE. It would be cool if I could also include attachments in the db.   So I don't think using the file path approach would work ?

Did you see my post?
No one commented on the post I made (nothing new here), so I guess nobody cares, lol.
But it's still an excuse for building a Web App :-)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now