Trying to tableize emails from user folders in outlook

Discussion in 'Access VBA Modules' started by DawnTreader, Dec 8, 2011.

  1. DawnTreader

    DawnTreader Guest

    Borrowed this code from a few different sources to try and hash something together that would run through the email folders and dump specific information from the emails to a table called tblInbox. at the moment i am trying to get it to work with just one folder with in the users data folders. for example the folders for this user are set up like so:

    Mailbox - Aftermarket
    -Completed (a email folder)
    -Algeria (a email folder)
    -Canada (another email folder) etc...

    i want to be able to get the emails in the completed folder and the sub folders algeria and canada and dump them to the table.

    here is my current code.

    Public Sub ImportMailFromOutlook()
    On Error GoTo ImportMailFromOutlook_Error
    ' This code is based in Microsoft Access.

    ' Set up DAO objects (uses existing "tblContacts" table)
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset("tblInbox")

    ' Set up Outlook objects.
    Dim outlookApp As New Outlook.Application
    Dim outlookNameS As Outlook.NameSpace
    Dim mainFolder As Outlook.mapifolder
    Dim mailFolder As Outlook.mapifolder
    Dim mail As Outlook.mailItem
    Dim objItems As Outlook.Items
    Dim iNumMail As Integer
    Dim i As Integer

    Set outlookNameS = outlookApp.GetNamespace("MAPI")
    ' Set mailFolder = outlookNameS.PickFolder

    ' Set mailFolder = outlookNameS.Folders '.GetDefaultFolder(olFolderInbox)
    ' Set mainFolder = outlookNameS.GetDefaultFolder( '.Folders("Canada") 'outlookNameS.Folders
    Set mailFolder = outlookNameS.Folders("Completed") 'mainFolder.Folders("Completed")
    Set objItems = mailFolder.Items
    iNumMail = objItems.Count
    If iNumMail <> 0 Then
    For i = 1 To iNumMail
    If TypeName(objItems(i)) = "MailItem" Then
    Set mail = objItems(i)
    rst.AddNew
    rst!OLID = mail.EntryID
    rst!To = mail.To
    rst!CC = mail.CC
    rst!Subject = mail.Subject
    rst!Body = mail.Body
    rst!DateReceived = mail.ReceivedTime
    rst!DateSent = mail.SentOn
    rst!Category = mail.Categories
    rst!ConversationIndex = mail.ConversationIndex
    rst!Conversation = mail.ConversationTopic
    rst!Importance = mail.Importance
    rst!From = mail.SenderEmailAddress
    rst!Region = mail.Parent
    rst.Update
    End If
    Next i
    rst.Close
    MsgBox "Finished."
    Else
    MsgBox "No Mail to export."
    End If

    ImportMailFromOutlook_Exit:
    Exit Sub

    ImportMailFromOutlook_Error:
    If Err.Number = 3022 Then
    Resume Next
    Else
    MsgBox "Error #: " & Err.Number & " " & Err.Description
    Resume ImportMailFromOutlook_Exit
    End If

    End Sub

    i am stuck on how to address the sub folders. i can get the actual inbox fine and if i use the pick folder method i can do each folder seperately but there are around 40 folders and that number will increase over time.

    is there a way to loop through and find each email folder and address it and then suck up the email data?

    if possible is there an "index" of the folders or do you have to path it?

    should i be posting this in the outlook forums? :)

    Any and all help appreciated.
     
    DawnTreader, Dec 8, 2011
    #1
    1. Advertisements

  2. DawnTreader

    HiTechCoach

    Joined:
    Dec 7, 2011
    Messages:
    6
    Likes Received:
    0
    Have you looked at the Outlook Object Model Overview at MSDN

    Helen Feddema also has an example you can download. I can't post links yet so do a google search for:

    +helenfeddema +"Working with Outlook folders"

     
    HiTechCoach, Dec 9, 2011
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Michael Medici

    Trying to send notification to Messenger.

    Michael Medici, Aug 5, 2003, in forum: Access VBA Modules
    Replies:
    0
    Views:
    97
    Michael Medici
    Aug 5, 2003
  2. J Bard
    Replies:
    2
    Views:
    178
    J Bard
    Dec 8, 2003
  3. camdonsquire
    Replies:
    1
    Views:
    202
    Guest
    Feb 8, 2005
  4. judith

    User defined output folders

    judith, Sep 14, 2005, in forum: Access VBA Modules
    Replies:
    1
    Views:
    72
    Douglas J Steele
    Sep 14, 2005
  5. RCMetrics
    Replies:
    2
    Views:
    84
    RCMetrics via AccessMonster.com
    Nov 10, 2005
  6. Scott Burke

    Trying to catch a bad user.

    Scott Burke, Aug 21, 2006, in forum: Access VBA Modules
    Replies:
    11
    Views:
    131
    Warren
    Aug 23, 2006
  7. ryguy7272

    Trying to Send Email, Via Outlook, Using VBA

    ryguy7272, Dec 1, 2008, in forum: Access VBA Modules
    Replies:
    11
    Views:
    176
    ryguy7272
    Dec 2, 2008
  8. tbrown7777
    Replies:
    10
    Views:
    171
    Pete D.
    Jan 4, 2009
Loading...