Solved

Access Reading Outlook Inbox subfolders

Posted on 2014-03-27
3
341 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 48

Expert Comment

by:Rgonzo1971
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now