Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access Reading Outlook Inbox subfolders

Posted on 2014-03-27
3
Medium Priority
?
363 Views
Last Modified: 2014-04-01
I'm working a project using Access 2010 to read an Outlook inbox and process the emails with attachments.  Using this example as a starting point I have the code working to read the Inbox itself but it won't read any of the subfolders in the Inbox

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23098837.html#a20708103

I have mulitple mailboxes and only want to run this on one specific box so when I call the function from the example I am providing the optional paremter to specify the mailbox

the example has this a comment
    'Cycle through the sub folders with recursive calls to this function

not sure if that means that it's supposed to read the subfolders as written or if I need to add something

I tried calling the function pointing to a specific subfolder but it doesn't work
             Set objResult = ReadFolder(strSubFolderName, objMyStore)

I'm facing serious deadlines on this so any help wlecome
0
Comment
Question by:CountryGirlMD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39960837
Hi,

If strSubFolderName and  objMyStore are the same folder, pls try only with strSubFolderName since objMyStore is optional

Regards
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 39960871
Taking a fresh eyes look then you want to process a fixed mailbox and all the items in the malbox?

Sub test()
    readFolders "Mailbox - Displayed mailbox name"
End Sub

Function readFolders(Optional strMailbox As String)
Dim objOL As Object
Dim fldr As Variant
Const olkFolderInbox As Integer = 6

    Set objOL = CreateObject("OUTLOOK.APPLICATION")
    If strMailbox = "" Then
        Set fldr = objOL.session.getdefaultfolder(olkFolderInbox)
    Else
        On Error Resume Next
        Set fldr = objOL.session.Folders(strMailbox)
        On Error GoTo 0
    End If
    If IsEmpty(fldr) Then
        MsgBox "oops - PST NOT FOUND"
    Else
        recurFolders fldr
    End If
End Function

Function recurFolders(rootFolder As Variant)
Dim subfolder As Variant
Dim itm As Variant

    'Do something wwith the folder
    Debug.Print rootFolder.folderpath
    For Each itm In rootFolder.items
        Debug.Print "  " & itm.Subject
    Next
    ' Finished with the folder
    For Each subfolder In rootFolder.Folders
        recurFolders subfolder
    Next
End Function

Open in new window


The only work this does is to print out simple details as you have no particular work load identified but you can either add the workload you want or use the recurfolders principle to iterate through all the subfolders in the original code.

Any questions just ask!

Chris
0
 

Author Closing Comment

by:CountryGirlMD
ID: 39969640
Thanks for the help -- it works great!

And it solved one other issue I was having with the other version of code - when it found a non mail item in the folder - like a meeting invite it just stopped as if it was done instead of skip to the next mail item - you have the 'itm' as Variant so it reads everything & I can use the message class to determine mail vs schedule items

So thanks again
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

722 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