Results 1 to 5 of 5

Thread: RE: Tracking if a message was sent with OL Reference

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    RE: Tracking if a message was sent with OL Reference

    Hey all, im using a createobject reference (see below) to call an outlook mail message... I wanted to track if it is sent or not so that I can take the final composed message and store it in a database (This is for message tracking from within my application) See code below, any suggestions would be helpful! Thanks!

    VB Code:
    1. Dim olMailItem
    2.     Dim olApp As Object
    3.     Dim objMail As Object
    4.         Set olApp = CreateObject("Outlook.Application")
    5.         Set objMail = olApp.CreateItem(olMailItem)
    6.  
    7.     Set objMail = olApp.CreateItem(olMailItem)
    8.  
    9.     With objMail
    10.         If (strRecipientName <> "") And (IsNull(strRecipientName) = False) Then .To = strRecipientName
    11.         .HTMLBody = strMailTemplateInfo
    12.         .Subject = "Critical Call IM" & KillZeros(Mid(frmMain.lblTickInfo.Caption, 3, 13)) & " - " & strMsgSubType & " - " & frmMain.txtKnownApps
    13.         On Error GoTo DialogOpen
    14.         .Display
    15.     End With
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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

    Re: Tracking if a message was sent with OL Reference

    Well you have created two instances of the email item object variable and only need one.

    You mean to determine if the user clicked send after the .Display line?
    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
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: Tracking if a message was sent with OL Reference

    your right, I totally did, well the first dim isnt even really used so I can remove that from my code.. But yes that is exactly what I want to do.... basically if the user closes the message, I want it to return to the app saying that the message was closed and not sent... but if they send, I want to capture the body, subject, and sent information before it goes out... The message is sent from a shared mailbox, so I cannot have the application go to the sent items folder and retrieve it... nor would I really want to, I would like to keep all activity as localized as possible

    Thanks!
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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

    Re: Tracking if a message was sent with OL Reference

    Ok, as long as you can place this macro code behind users Outlook VBA class you can track all outgoing email.
    VB Code:
    1. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    2.     'Write out to a log or save info to a file etc.
    3.  
    4. End Sub
    If not then you can show the message Modally and test for the email object variable still being instanciated. If its not then they closed the inspector window.
    VB Code:
    1. .Display vbModal
    2.     If TypeName(objMail) = "Nothing" Then
    3.         MsgBox "Forgot to send email before closing"
    4.     End If
    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
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: Tracking if a message was sent with OL Reference

    I would actually like to stay away from putting VBA in outlook, I want all coding to be completely on my application side

    is there a way that I can get the message contents out of it when it gets sent?
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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