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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Email from 2nd Inbox

Status
Not open for further replies.

PortyAL

Technical User
May 13, 2005
126
GB
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:

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

 
When organizations used to have Public Folders on Exchange...

Code:
Set OutNameSpace = OutApp.GetNamespace("MAPI")
Set OutFolder = OutNameSpace.Folders("Public Folders").Folders("All Public Folders").Folders("Call Report")

The above would have OutFolder set to the "Call Report" subfolder. Technically it was a nested path as you can see. My hunch is that the same folders collection would navigate the mailboxes... or you might be able to loop through them and find the ones that begin "Mailbox". Keep in mind, you will see personal folders looping this way.

I hope this helps you get to the right place. It has been a long while since I dipped my toe in Outlook object model. If you figure it out, please remember to post back for the next guy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top