Hi
I use the following code to select an email from my inbox, save it as a file and create a link to that file in an Access application:
This has worked fine up to now as I've only had 1 email address and inbox. However I now have a second email address and therefore a second inbox. I need therefore to be able to choose the Inbox I wish to grab the email from. Has anyone any suggestions how to do this via code as I am not permitted to tinker with the settings on my Outlook accounts?
Many thanks
AL
I use the following code to select an email from my inbox, save it as a file and create a link to that file in an Access application:
Code:
If Me.docfolder = "" Then GoTo nofolder
Dim ns As Outlook.Namespace
Dim sent As Outlook.MAPIFolder
Dim temp As Outlook.MAPIFolder
Dim I As Integer
Dim J As Integer
Dim email As MailItem
Dim att As Attachment
Dim emailname As String
Set ns = GetNamespace("MAPI")
Set temp = ns.GetDefaultFolder(olFolderInbox)
For I = temp.Items.Count To 1 Step -1
If temp.Items(I).Class <> 43 Then GoTo nexti:
If temp.Items(I).FlagStatus = olFlagComplete Then
temp.Items(I).FlagStatus = olNoFlag
temp.Items(I).Save
Me.tbl_Correspondence_subform2.SetFocus
DoCmd.GoToRecord , , acNewRec
Me.tbl_Correspondence_subform2!Date = temp.Items.Item(I).ReceivedTime
Me.tbl_Correspondence_subform2!Details = "From: " & temp.Items(I).SenderName & " - " & temp.Items.Item(I).Subject
emailname = Forms!form1!docfolder & "\Email " & Me.tbl_Correspondence_subform2!ID & ".msg"
temp.Items(I).SaveAs emailname, olMSG
Me.tbl_Correspondence_subform2!Link = "Email#" & emailname & "#"
If temp.Items(I).Attachments.Count > 0 Then GoTo addatt
Exit Sub
addatt:
Dim K As Integer
For K = 1 To temp.Items(I).Attachments.Count
temp.Items(I).Attachments.Item(K).SaveAsFile Forms!form1!docfolder & "\" & _
temp.Items(I).Attachments.Item(K).DisplayName
Next K
Exit Sub
End If
nexti:
Next I
Set temp = Nothing
Set ns = Nothing
Exit Sub
nofolder:
MsgBox "Document folder has not been specified.", vbInformation, "Cannot continue"
Me.Document_folder.SetFocus
This has worked fine up to now as I've only had 1 email address and inbox. However I now have a second email address and therefore a second inbox. I need therefore to be able to choose the Inbox I wish to grab the email from. Has anyone any suggestions how to do this via code as I am not permitted to tinker with the settings on my Outlook accounts?
Many thanks
AL