Results 1 to 10 of 10

Thread: [RESOLVED] Outlook - Delete Saved Messages

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Resolved [RESOLVED] Outlook - Delete Saved Messages

    Newbie here...I need help and was wondering if anybody could give me a code sample. I am running Outlook 2003 and WinXP Home. I currently have an Outlook add-in that creates contacts via sent mail. Then I have a rule that sends a copy of a sent message with certain words in the subject to a specific folder. What I want to do is when a person responds to my initial email, (he would already be saved as a contact), I want that copy of the original message deleted. That way when I go to follow up to my initial contact, I am not sending a follow up email to someone that has already responded. I hope that I have done a good enough job of explaining this problem, PLEASE HELP ME!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook - Delete Saved Messages

    Welcome to the Forums.

    You would search the items collection of the mapifolder where your sent message copies are saved to. Then when found you can use
    the .Delete method of the mailitem.

    Search with my username and "Outlook" for many examples.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: Outlook - Delete Saved Messages

    RobDog888, I have absolutely no programming experience, so I was wondering if there was some code sample that someone could post that could be inserted into ThisOutlookSession module that could help me. I know that is a huge favor for someone to write it for me, but it would be greatly appreciated. Thanks.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook - Delete Saved Messages

    See my code in this thread. It moves the items as they are added to a folder but you just need to use the.Delete method instead and
    change to point to the folder your wanting to monitor.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: Outlook - Delete Saved Messages

    bump

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook - Delete Saved Messages

    This will delete any message that comes into your Inbox folder with the matching criteria of "RE: ABC" in the message's subject.
    VB Code:
    1. 'ThisOutlookSession
    2. Option Explicit
    3.  
    4. Public WithEvents InboxItemsAdd As Items
    5.  
    6. Private Sub Application_MAPILogonComplete()
    7.     Set InboxItemsAdd = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
    8. End Sub
    9.  
    10. Private Sub InboxItemsAdd_ItemAdd(ByVal Item As Object)
    11.     If Item.Subject = "RE: ABC" Then
    12.         Item.Delete
    13.     End If
    14. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: Outlook - Delete Saved Messages

    okay, but what if I want to delete all previous messages that i have sent to this person that are in folders other than the inbox?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook - Delete Saved Messages

    You would need to do a .Find and if your sure you will only be returning corect results the you can loop theough the .Find and
    .Delete each of them.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    5

    Re: Outlook - Delete Saved Messages

    any code describing this .find method?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Outlook - Delete Saved Messages

    Find example from the help file...
    VB Code:
    1. Sub FindContact()
    2. 'Finds and displays last contacted info for a contact
    3.  
    4.     Dim olApp As Outlook.Application
    5.     Dim objContact As Outlook.ContactItem
    6.     Dim objContacts As Outlook.MAPIFolder
    7.     Dim objNameSpace As Outlook.NameSpace
    8.  
    9.     Set olApp = CreateObject("Outlook.Application")
    10.     Set objNameSpace = olApp.GetNamespace("MAPI")
    11.     Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
    12.     Set objContact = objContacts.Items.Find("[FileAs] = ""Smith, Jeff"" and [FirstName] = ""Jeff""")
    13.     If Not TypeName(objContact) = "Nothing" Then
    14.         MsgBox "Found"
    15.     Else
    16.         MsgBox "Contact not found."
    17.     End If
    18. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width