Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Outlook: Add User Property when Item added - reliably with exchange host server?

Outlook: Add User Property when Item added - reliably with exchange host server?

Outlook: Add User Property when Item added - reliably with exchange host server?

I use a user property ("ReceivedDateOnly") to group on a received date in MM/dd/yyyy format and then subsequently sort on the real received date sorted on time hh:mm format.

The below code was usually reliable in Outlook 2013. Since migrating to Outlook 2016, I have had a lot of problems.

I know there is an alternate method that is allegedly better for handling processing the larger batches of e-mails that happens with an Exchange host but I lost my note and while this is an enormous pain in my side, I don't have the time to research it...

I now have more send/receives where it fails to populate the user property than successes even small batches. I have blown away my OST and reran everything which seemed to help for a few days and now back to the same behavior.

Aside from code, any other insights that I can take to the Help desk would be welcome too.


Option Explicit

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  ' default local Inbox
  Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)

  On Error GoTo ErrorHandler
  Dim dtReceived As Date
  Dim objProp As Outlook.UserProperty
  Select Case TypeName(Item)
    Case "ReportItem" 'NDR's - Non Delivery Reports
        dtReceived = Item.CreationTime 'Looks like this is the "Received Date"
    Case Else 'MailItem and MeetingItem I definitely saw working
      dtReceived = Item.ReceivedTime
  End Select
  'MsgBox "Date Received is" & dtReceived 'Yes it is running
 'Property added below needs added to inbox view if you want to see or group on it
  Set objProp = Item.UserProperties.Add("ReceivedDateOnly", olDateTime, True)
  objProp.Value = DateSerial(Year(dtReceived), Month(dtReceived), Day(dtReceived))
  Item.Save 'item needs saved now that it has been updated
  Exit Sub
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close