|
Lance Friedemann
Posts: 24
Joined: 2017-02-10
|
I'm looking for a way to pass the textbox information from the original Outlook message to the new message form when the user hits reply. I really only need to grab one textbox field and then I can query the database when the form loads.
In the OutlookItemsEventsClass I tried:
Public Overrides Sub ProcessReply(ByVal response As Object, ByVal e As AddinExpress.MSO.ADXCancelEventArgs)
If TypeOf Me.ItemObj Is Outlook.MailItem Then
Dim mail As Outlook.MailItem = TryCast(Me.ItemObj, Outlook.MailItem)
If mail IsNot Nothing Then
'******I THINK THIS IS RETURNING THE NEW FORM ON THE REPLY WHICH DOESN"T HAVE A ADXOLForm1_Ticket loaded yet. I need the ORIGINAL form before the reply was hit.
Dim theForm As ADXOutlookTicket.ADXOlForm1_Ticket = TryCast(ADXOutlookTicket.ADXOlForm1_Ticket.ActiveForm, ADXOutlookTicket.ADXOlForm1_Ticket)
Dim pk As String = theForm.TickTxt.Text
End If
End If
End Sub
|
|
Posted 23 Feb, 2017 17:03:10
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hello Lance,
Add-in Express forms show/hide according to the corresponding Outlook windows getting shown or hidden. This may not coincide with Outlook events. That is, the Reply event may fire before or after the original item's inspector is hidden.
To work around this, save globally the data of the form shown in the original item's inspector. When the form in the reply item's inspector gets shown, it may retrieve the data and use them as required.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 24 Feb, 2017 05:37:20
|
|
Top
|
|
Lance Friedemann
Posts: 24
Joined: 2017-02-10
|
Thanks Andrei,
I created a separate Class called GobalVars.vb and declared my variables like this:
Public Class GlobalVars
Public Shared GloMsgID As String = Nothing
Public Shared GloPK As String = Nothing
Public Shared GloClosedChk As Boolean = False
End Class
Then inside OutlookItemEventsClass1.vb:
Public Overrides Sub ProcessReply(ByVal response As Object, ByVal e As AddinExpress.MSO.ADXCancelEventArgs)
'This detects if the Reply or ReplyAll button has been hit.
If TypeOf Me.ItemObj Is Outlook.MailItem Then
Dim mail As Outlook.MailItem = TryCast(Me.ItemObj, Outlook.MailItem)
If mail IsNot Nothing Then
GloMsgID = mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") 'Grab the MessageHeader and apply it to the global variable GloMsgID so it can be used when the ADXForm1 loads.
Marshal.ReleaseComObject(mail)
End If
End If
End Sub
Added these to AddinModule.vb:
Private adxOutlookItem As OutlookItemEventsClass1
Private Sub AddinModule_AddinStartupComplete(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.AddinStartupComplete
'SUB 1 of 3 - THIS IS FIRED WHEN OUTLOOK STARTS
Debug.Print("The AddinStartupComplete event has occurred.")
Debug.Print("The add-in has been loaded by Outlook " & Me.HostMajorVersion.ToString())
' This creates an instance of the class that handles the events of an Outlook item
adxOutlookItem = New OutlookItemEventsClass1(Me) '<-- Creates the instance when Outlook starts for detecing outlook events
End Sub
Private Sub AddinModule_AddinBeginShutdown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.AddinBeginShutdown
'SUB 2 of 3
' this event may not occur in Outlook 2010, see the blog post 'Outlook 2010 Fast Shutdown feature'
' at http://www.add-in-express.com/creating-addins-blog/2010/05/04/outlook2010-fast-shutdown/
Debug.Print("The AddinBeginShutdown event has occurred.")
If adxOutlookItem.IsConnected Then
adxOutlookItem.RemoveConnection()
Debug.Print("Disconnected from the previously connected item.")
End If
adxOutlookItem = Nothing
End Sub
Private Sub adxOutlookEvents_InspectorActivate(ByVal sender As System.Object, ByVal inspector As System.Object, ByVal folderName As System.String) Handles AdxOutlookAppEvents1.InspectorActivate
'SUB 3 of 3 - THIS FIRES WHEN THE INSPECTOR WINDOW IS OPENED
Debug.Print("The InspectorActivate event has occurred.")
Dim theInspector As Outlook.Inspector = TryCast(inspector, Outlook.Inspector)
If theInspector IsNot Nothing Then
Dim item As Object = theInspector.CurrentItem
If TypeOf item Is Outlook.MailItem Then
If adxOutlookItem.IsConnected Then
adxOutlookItem.RemoveConnection()
Debug.Print("Disconnected from the previously connected item.")
End If
adxOutlookItem.ConnectTo(item, True)
Else
Marshal.ReleaseComObject(item)
End If
End If
End Sub
Private Sub adxOutlookEvents_ItemSend(sender As System.Object, e As AddinExpress.MSO.ADXOlItemSendEventArgs) Handles AdxOutlookAppEvents1.ItemSend
'Grabs the Send button event from the active Outlook window
If Not IsNothing(GloPK) And GloClosedChk = True Then 'don't do anything if your form was never loaded
MessageBox.Show("You checked the Closed Checkbox for: " & GloPK & "!")
'do stuff like write to a database with your global variables
ElseIf Not IsNothing(GloPK) Then
MessageBox.Show(GloPK & " at send.")
'do other stuff
End If
End Sub
Finally, do some stuff in the ADXOLForm1:
Public Sub ADXOlForm1_ADXBeforeFormShow() Handles MyBase.ADXBeforeFormShow
'Query your database set/pass the global variables here
'Or you could decide not to load the form at all:
Call WipeGlobals()
Me.Close()
End Sub
Private Sub WipeGlobals()
'clear all of the variables if you didn't use the form
GloMsgID = Nothing
GloPK = Nothing
GloClosedChk = False
End Sub
Private Sub ADXFormShow() Handles MyBase.ADXAfterFormShow
GloPK = Me.TickTxt.Text 'Set the global variable after the form shows.
'MessageBox.Show(GloPK & " ADXAfterFormShow")
End Sub
I've really struggled through this so I hope it helps someone else. |
|
Posted 24 Feb, 2017 20:21:44
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hello Lance,
Thank you for posting this!
Two small notes.
1. Releasing mail in ProcessReply, you also release the COM object that Add-in Express provides via the Me.ItemObj property. Releasing this COM object effectively prevents getting further events from that COM object.
2. We recommend setting Me.Visible in ADXOlForm1_ADXBeforeFormShow; not calling Me.Close.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 27 Feb, 2017 05:29:25
|
|
Top
|
|
Lance Friedemann
Posts: 24
Joined: 2017-02-10
|
Andrei,
Are you saying to just leave the mail object unreleased or do I need to release some other Outlook object?
Lance |
|
Posted 27 Feb, 2017 10:31:53
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hello Lance,
Lance Friedemann writes:
Are you saying to just leave the mail object unreleased or do I need to release some other Outlook object?
Since Dim mail As Outlook.MailItem = TryCast(Me.ItemObj, Outlook.MailItem) doesn't create a new COM object, the mail variable and the Me.ItemObj property refer to the same COM object. Releasing the variable releases that COM object and this may cause problems if you expect events to work.
The COM object returned by Me.ItemObj will be released automatically when you call adxOutlookItem.RemoveConnection; this is so because you call ConnectTo(item, True) - True means: "release the COM object when RemoveConnection is called".
Andrei Smolin
Add-in Express Team Leader |
|
Posted 28 Feb, 2017 04:38:50
|
|
Top
|
|