Solved

Access Reading Outlook Inbox subfolders

Posted on 2014-03-27
3
361 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

636 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