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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks