?
Solved

Can't get the Received Date on Outlook using VBA

Posted on 2009-04-06
1
Medium Priority
?
4,118 Views
Last Modified: 2012-05-06
I'm trying to retrieve all the emails from a specific folder from my MS Outlook including those in its subfolders.  Using the code below, I can get the Subject, To, Body, Importance but not the Received.  It just shows blank.  When I try to get the value using the immediate window, it says " Run-time error 438:  Object doesn't support this property or method."  I need to get the Received date so I can filter the date the emails were received.

I will appreciate any help!
Private Sub cmdRefresh_click()   
    Dim olApp As Outlook.Application
    Dim olNs As Outlook.NameSpace
    Dim strFolderPath As String    
    DoCmd.SetWarnings (False)
    DoCmd.RunSQL "Delete * from LastWeek"
    DoCmd.SetWarnings (True)           
    Dim RS As New ADODB.Recordset
    RS.Open "Emails", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    Set olApp = New Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")    
    Dim olFldr As Outlook.MAPIFolder     
    Set olFldr = olNs.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Transactions")    
    Call ProcessFolder(olFldr)
End Sub
 
 
Sub ProcessFolder(StartFolder As MAPIFolder)
 
    Dim objFolder As Outlook.MAPIFolder
    Dim objItem As Object
    Dim objEmail As MailItem
    Dim mailObject As Object
    Dim dtReceived As Date
    Dim strSubject As String
        On Error Resume Next
    Set objApp1 = Outlook.Application
    Set objNS1 = objApp1.GetNamespace("MAPI")
    Dim RS As New ADODB.Recordset
    RS.Open "LastWeek", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
   
    For Each objItem In StartFolder.Items '.Folders           
            strSubject = objItem.Subject
            dtReceived = CDate(objItem.Received)
            If (InStr(1, strSubject, "Clothes;") > 0) Or _
                (InStr(1, strSubject, "Shoes") > 0) Then                            
                With RS
                    .AddNew
                    !Importance = objItem.Importance
                    !Subject = objItem.Subject
                    !from = objItem.SenderName
                    !To = objItem.To
                   ' ![Normalized Subject] = objItem.[Normalized Subject]
                    !Received = objItem.Received
                    .Update
                End With
            End If
        Next
 
        For Each objFolder In StartFolder.Folders
            Call ProcessFolder(objFolder)
        Next
End Sub

Open in new window

0
Comment
Question by:meredithf
[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
1 Comment
 

Accepted Solution

by:
meredithf earned 0 total points
ID: 24076687
I got it!  Should be objItem.ReceivedTime.

Thanks!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

800 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