Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access Reading Outlook Inbox subfolders

Posted on 2014-03-27
3
Medium Priority
?
365 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
3 Comments
 
LVL 53

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

916 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