Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Email unique identifier (Primary Key) in Outlook???

Posted on 2008-10-02
13
Medium Priority
?
2,064 Views
Last Modified: 2012-05-05
Do the emails in Outlook have some unique identifier (Primary Key)?

In Access environment, I am reading email information and storing them in a table. I wonder it there is a unique identifier for each email. I want to read its value and store in my table along the rest of information on the emails (like SendOn, SentBy, Subject, etc.).

I already have the code to read email data. If applicable, what is the field name for "email unique identifier"?

Thank you.
0
Comment
Question by:Mike Eghtebas
[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
  • 7
  • 6
13 Comments
 
LVL 2

Expert Comment

by:doublebug
ID: 22627648
Every message in the Outlook have uniques identifier
EntryID. It is binary property but via Outlook Object Model it is available as hex encoded string. You can use this property to open message via GetItemFromID method. The behavior of this identifier is a bit different for PST and Exchange providers.
When message is moved between folders in the same store PST EntryID stays the same.
In Exchange EntryID changes.
Also there is PR_SEARCH_KEY property. It is not available via OOM but you can use some IMAPIProp interface wrappers like Redemption (http://www.dimastr.com/redemption/). This property says the same if message is moved between folders but then message is copied copy has the same value.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22627964
With strQuery = "[EntryID] = '" & strEntryID & "'"

I am getting the following error at:

Set olkItem = OlkFolder.Items.Find(strQuery)   '<--- ERORRS HERE *********

How can I correct this.

Thanks,

Mike
Public Sub OpenEmail(lngEmailID As Long)
 
    Dim strEntryID As String
    Dim lngFolderID As Long
    Dim strFolder As String
    
    lngFolderID = DLookup("EmailFolder_ID", "tEmails", "EmailID=" & lngEmailID)
    strFolder = DLookup("FolderPath", "tOLK_Folders", "ID=" & lngFolderID)
    strEntryID = DLookup("EntryID", "tEmails", "EmailID=" & lngEmailID)
 
    Call SearchForItem(strEntryID, strFolder)
 
End Sub
 
Public Sub SearchForItem(strEntryID As String, strOlkFolder As String)
 
    Dim obj_CurrentOlkFolder As Outlook.MAPIFolder
    Dim olkApp As Object, _
        olkNS As Object, _
        OlkFolder As Object, _
        olkItem As Object, _
        strQuery As String
    Set olkApp = GetObject(, "Outlook.Application")
    Set olkNS = olkApp.Session
    Set OlkFolder = GetOutlookFolder(strOlkFolder)
    strQuery = "[EntryID] = '" & strEntryID & "'" 
    Set olkItem = OlkFolder.Items.Find(strQuery)   '<--- ERORRS HERE *********
    If TypeName(olkItem) = "nothing" Then
        MsgBox "No match found"
    Else
        olkItem.Display
    End If
    Set OlkFolder = Nothing
    Set olkNS = Nothing
    Set olkApp = Nothing
End Sub

Open in new window

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22627981
Following is a sample strQuery:
[EntryID] = '0000000088A29984A2A46240B4D83F2C6FEE9F560700CD46E9B936EFE5479CB85F1F510A078600000036EF4B0000FDA9D25B22E75D4E802E9D3D59692152000000DA44560000'

Open in new window

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22628037
I forgot to submit the error description:

The property EntryID in the condition is not valid.

I was thinking EntryID will be recognized. Why it is not?

Mike

0
 
LVL 2

Expert Comment

by:doublebug
ID: 22628044
Use olkNS.GetItemFromID to open an item.
0
 
LVL 2

Expert Comment

by:doublebug
ID: 22628120
EntryID is unique property and you don't need to use it in search.
This property is used to open objects in an Outlook store. That is by design.
In the underlying store (MAPI store provider) you open object by using
IMAPISession::OpenEntry function.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22628234
Do you mean like:

Public Sub SearchForItem(strEntryID As String, strOlkFolder As String)
                                                   'not used--------------^
    Dim obj_CurrentOlkFolder As Outlook.MAPIFolder
    Dim olkApp As Object, _
        olkNS As Object, _
        OlkFolder As Object, _
        olkItem As Object, _
        strQuery As String
    Set olkApp = GetObject(, "Outlook.Application")
    Set olkNS = olkApp.Session

    olkNS.GetItemFromID(strEntryID) '<------******
 
    Set OlkFolder = Nothing
    Set olkNS = Nothing
    Set olkApp = Nothing
End Sub

?
0
 
LVL 2

Expert Comment

by:doublebug
ID: 22628257
yes
0
 
LVL 2

Expert Comment

by:doublebug
ID: 22628273
And you may need to open all stores. Because if store that holds this object is not opened the call will fail.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22628370
It doen't produce error but it doesn't open any email either.


re:> need to open all stores

I don't know what this means. Here, what do you mean by store and how do I know it is open?

Thanks,

Mike
0
 
LVL 2

Accepted Solution

by:
doublebug earned 2000 total points
ID: 22628457
You need to use.
Set olkItem = olkNS.GetItemFromID(strEntryID)
If TypeName(olkItem) = "nothing" Then
        MsgBox "No match found"
Else
        olkItem.Display
End If
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22628583
Beautiful!

Thank you,

Mike
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 22635246
doublebug,

I have a follow-up question at:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_23785451.html#a22635227

I appreciated an input from you.

Mike
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

721 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