+ Reply to Thread
Results 1 to 2 of 2

Thread: Import e-mail details to an access db

  1. #1
    Forum Guru jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    San Antonio, TX
    MS-Off Ver
    Excel 2007
    Posts
    2,581

    Import e-mail details to an access db

    This code runs and stores the subject in the subject field of my db, but if I add the lines From, To, Body, etc., I get an error.

    Method 'SenderName' of object _MailItem' failed

    The field in the db is SenderName and text 255.

    I pulled the code from here http://www.blueclaw-db.com/read_emai...ss_outlook.htm

    Any thoughts?

    Also, how do change the folder I want to evaluate for data?

    Private Sub Command0_Click()
    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim OlApp As Outlook.Application
    Dim Inbox As Outlook.MAPIFolder
    Dim InboxItems As Outlook.Items
    Dim Mailobject As Object
    DoCmd.RunSQL "Delete * from tbl_outlooktemp"
    Set db = CurrentDb
    
    Set OlApp = CreateObject("Outlook.Application")
    Set Inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
    Set rst = CurrentDb.OpenRecordset("tbl_OutlookTemp")
    
    Set InboxItems = Inbox.Items
    
    For Each Mailobject In InboxItems
        If Mailobject.UnRead Then
            With rst
                .AddNew
                    !Subject = Mailobject.Subject
    '                !From = Mailobject.SenderName
    '                !To = Mailobject.To
    '                !Body = Mailobject.Body
    '                !DateSent = Mailobject.SentOn
                    .Update
                    Mailobject.UnRead = False
            End With
        End If
    Next
    
    Set OlApp = Nothing
    Set Inbox = Nothing
    Set InboxItems = Nothing
    Set Mailobject = Nothing
    Set rst = Nothing
    
    End Sub

  2. #2
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Import e-mail details to an access db

    Don't know how you've got on with this but here's an example of how to display a dialogue allowing you to pick a folder to work on:

    Sub ExtractRecipientsFromEmail()
    
    Dim MailObject As Object
    Dim myfolder As MAPIFolder
    
    Set myfolder = ThisOutlookSession.Session.PickFolder
    
    If myfolder Is Nothing Then Exit Sub
    
    For Each MailObject In myfolder.Items
    
        If MailObject.Class = olMail Then
        
            Debug.Print MailObject.SenderName
    
        End If
    
    Next
    
    Set MailObject = Nothing
    
    End Sub

    Hope it helps,

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0