Reading mail into Access from Outlook

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Hello,

I use this code to read/scan e-mail that I receive through Outlook,
into a table in Access. However, I am having a problem proccessing the
attachments. My first question is - What is the proper code to input to
properly handle attachments (see code below). Also, what are the ways I
can store the attachments in the table, for example - will the
attachment(s) store locally and a path will be stored in the attachment
field of the table? The code I use is below. Thanks very much for your
time.

- Dan


Private Sub Command0_Click()
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
'DoCmd.RunSQL "Delete * from incomingmail"
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set TempRst = CurrentDb.OpenRecordset("incomingmail")
'
Set InboxItems = Inbox.Items
'
For Each Mailobject In InboxItems
If Mailobject.UnRead Then

With TempRst

.AddNew
!Attachments = Mailobject.Attachments *(does not work)*
!Subject = Mailobject.Subject
!from = Mailobject.SenderName
!To = Mailobject.To
!Body = Mailobject.Body
!DateSent = Mailobject.SentOn
!SizeKB = Mailobject.Size
.Update
Mailobject.UnRead = False
End With
End If
Next

Set OlApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
End Sub
 
Just to quickly follow up:

I added (1) to the end of the attachment code:

!Attachments = Mailobject.Attachments(1)

And that enabled the name of the attachment to import into Access but
that was it.


Thanks again for your help,
Dan
 
Back
Top