Solved

Access Reading Outlook Inbox subfolders

Posted on 2014-03-27
3
345 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Moving SharePoint 3.0 role to differen server 7 47
Help writing a query 6 73
Unrecognized Database Format 8 93
ms access 2013, running .mdb 2 31
This collection of functions covers all the normal rounding methods of just about any numeric value.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

895 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

16 Experts available now in Live!

Get 1:1 Help Now