Results 1 to 6 of 6
  1. #1
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142

    Reference specific outlook email from access

    Here's the workflow I'm looking to achieve:

    1. When I receive a request for pricing email in outlook I will have a button within outlook that will show a short input form for things like due date, etc. and record this info in an access database. How do I go about saving a reference (id?) to a specific email in an access table?
    2. From Access I need to be able to initiate a reply email to that specific email saved in step 1. How would I find it and do that?




    I have no idea the best way to reference outlook email (objects?). Do I add some kind of tag or my own unique id to the original email somehow? Do reliably unique id's already exist within an email?

    TIA. I'm completely new to outlook vba.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You can use the EntryID property to store in Access and identify the email
    https://docs.microsoft.com/en-us/off...ilitem.entryid
    Please feel free to download my free utility (http://forestbyte.com/ms-access-util...ook-companion/ ) that should have most of the code needed to solve your task.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Excellent, thank you Gicu!

    This looks like the ticket:
    Code:
    strEntryId = Me.lstNewEmail
    Set ObjOutlook = CreateObject("Outlook.Application", "localhost")
    Set myNameSpace = ObjOutlook.GetNamespace("MAPI")
    Set oMailItem = myNameSpace.GetItemFromID(strEntryId)
    oMailItem.Display
    It looks like EntryID changes if the message is moved to a different folder in outlook... that shouldn't be a problem for me.
    https://docs.microsoft.com/en-us/off...ilitem.entryid

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You're very welcome!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I've learned that EntryID will not stay constant in certain conditions. I've learned that PR_SEARCH_KEY may be a better property to rely on as a unique identifier but I can't figure out how to find an email using this property. Any ideas?

    Code:
    Public Sub search_test(key As String)
        
        Dim olNS As NameSpace
        Dim FolderInbox As MAPIFolder
        Dim filtered_items As Items
        Dim olMail As MailItem
        Dim strFilter As String
        
        Set olNS = GetNamespace("MAPI")
        Set FolderInbox = olNS.GetDefaultFolder(olFolderInbox)
        
        'strFilter = "@SQL= urn:schemas:httpmail:subject LIKE '%Notice Regarding%'"
        'strFilter = "@SQL= urn:schemas:httpmail:textdescription LIKE '%<Email Body>%'"
        strFilter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x300B0102"" = '" & key & "'"
    
        Set filtered_items = FolderInbox.Items.Restrict(strFilter)
        
        If filtered_items.Count = 0 Then
            GoTo empty_objects
        End If
        
        For Each olMail In filtered_items
            
            Debug.Print olMail.Subject
            Debug.Print olMail.SenderEmailAddress
            
        Next olMail
        
    empty_objects:
        Set FolderInbox = Nothing
        Set olNS = Nothing
        
    End Sub

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    What is the value of the key argument that you are passing to the sub?
    Some additional reading: https://groups.google.com/g/microsof...da8a356076e683 (from https://stackoverflow.com/questions/...-pr-search-key)
    Looks like pr_search_key does not work with Find\Restrict:
    https://stackoverflow.com/questions/...ges-when-email
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 06-19-2020, 03:44 PM
  2. Replies: 4
    Last Post: 07-12-2018, 05:38 AM
  3. Replies: 2
    Last Post: 06-27-2018, 02:27 PM
  4. Replies: 5
    Last Post: 03-23-2017, 06:38 AM
  5. Runtime Access & Outlook library reference
    By Ruegen in forum Access
    Replies: 16
    Last Post: 12-10-2013, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums