>news:1165860242.511610.180500@73g2000cwn.googlegr oups.com...
Quote:
Dean Spencer wrote:
>Can anyone help? I am importing Emails from Outlook using the
>following
>code:
>>
>Public Function ScanInbox(SubjectLine As String)
> Dim TempRst As Recordset
> Dim OlApp As Outlook.Application
> Dim Inbox As Outlook.MAPIFolder
> Dim InboxItems As Outlook.Items
> Dim Mailobject As Object
> Set OlApp = CreateObject("Outlook.Application")
> Set Inbox =
>OlApp.GetNamespace("Mapi").GetDefaultFolder(olFol derInbox)
> Set TempRst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
> If SubjectLine <"" Then
> Set InboxItems = Inbox.Items.Restrict("[Subject] = """ &
>SubjectLine
>& """")
> Else
> Set InboxItems = Inbox.Items
> End If
> For Each Mailobject In InboxItems
> With TempRst
> On Error Resume Next
> .AddNew
> !Subject = Mailobject.Subject
> !From = Mailobject.SenderName
> !To = Mailobject.To
> !Body = Mailobject.Body
> !DateSent = Mailobject.SentOn
> !Attachment = Mailobject.Attachment
> .Update
> 'Mailobject.Delete
> Mailobject.Read
> End With
> Next
>>
> Set OlApp = Nothing
> Set Inbox = Nothing
> Set InboxItems = Nothing
> Set Mailobject = Nothing
> Set TempRst = Nothing
>End Function
>>
>>
>The emails which I would like to import contain an attachment. Does
>anyone
>know how I can either save the attachement in Access as a memo or OLE
>object? or even save a link to open the attachement?
>>
>I have tried adding !Attachment = Mailobject.Attachment but nothing is
>added
>to the temporary table?
>>
>Thank you for your help.
>>
>Dean Spencer.
>
Hi, Dean.
>
Your question is really about the Outlook object model and not about
Access per se. That said, if you check the Object Browser you will see
that there is no "Attachment" property for the MailItem object.
However, there _is_ an "Attachments" collection through which you can
access the attachment(s) for the MailItem. (A single mail message can
have more than one attachment.)
>
So, your reference to the ".Attachment" property won't work. You can
either arbitrarily select the first attachment, something like this
(warning - air code):
>
>
Dim oMail As Outlook.MailItem, oAttach As Outlook.Attachment
>
' ...omitted code to set up object references, open recordset, etc.
>
If oMail.Attachments.Count 0 Then
Set oAttach = oMail.Attachments(0)
' do something useful
Set oAttach = Nothing
End If
>
>
or you could iterate through the Attachments collection, as in
>
>
Dim oMail As Outlook.MailItem, oAttach As Outlook.Attachment
>
' ...omitted code to set up object references, open recordset, etc.
>
For Each oAttach In oMail.Attachments
' do something useful
Next
Set oAttach = Nothing
>