Results 1 to 3 of 3

Thread: Outlook Event

  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    856
    Thanks
    0
    Thanked 9 Times in 8 Posts

    Outlook Event

    I'm having difficulty with an Outlook event, and the material I've found at the Microsoft site doesn't quite work for me.

    The code, quite simplified, is as follows:

    Code:
    Public WithEvents myItem As Outlook.ContactItem
     
    Private Sub myItem_BeforeDelete(ByVal Item As Object, Cancel As Boolean)
        On Error Resume Next
        Dim strPrompt As String
     
        strPrompt = "This looks like a shared Contact. Are you sure you want to delete the item?"
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbNo Then
            'Don't delete the item
            Cancel = True
        End If
        
    End Sub
    
    Public Sub DeleteContact()
        Set myItem = Application.ActiveInspector.CurrentItem
        On Error Resume Next
        myItem.Delete
    End Sub
    This works only if I run macro DeleteContact; I would like it to run at any and all Delete Contacts events. (I understand this can be trapped in Inspector view only.) If I run DeleteContact once, the BeforeDelete events fires from the Delete button on the Ribbon subsequently. But it appears to do so only when I've clickec No the first time, and then click the Delete button on the same Contact.

    What is necessary to initialize ContactItem_BeforeDelete so that it always fires.

    Thanks.
    Richard Barrett

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Administrator
    Join Date
    Mar 2001
    Location
    St Louis, Missouri, USA
    Posts
    20,381
    Thanks
    1
    Thanked 595 Times in 532 Posts
    Which version of Outlook?

    Joe

  4. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    856
    Thanks
    0
    Thanked 9 Times in 8 Posts
    Edit: I think I've resolved this. I trap a new Inspector, and then if it's a ContactItem, I set the item object. So I always have the contact item, regardless of the folder (default contacts) or otherwise.

    Sorry, I should have mentioned that. Outlook 2010 (and soon 2013). I have the code in the ThisOutlookSession module.

    Richard
    Last edited by richardbarrett; 2014-07-12 at 17:25.

Posting Permissions

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