Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   open event problem (http://www.outlookbanter.com/outlook-vba/58972-open-event-problem.html)

Kenny October 15th 07 10:29 AM

open event problem
 
Hi,
I made a function which handles the open event for a mailitem
Seems to work pretty well, but now that I look closely, I found out that
it's not working that well.

Some time I will see that the function is launch and other time not for no
reason I just keep clicking on different mailitem and work and not work, here
is my function

Private Sub oMailItem_Open(ByRef cancel As Boolean) Handles oMailItem.Open
cancel = False
Try
If (oMailItem.ConversationIndex "") Then
If (My.Settings.UseSocket) Then
oSender.MailOpened(oMailItem)
End If
End If
Catch ex As SystemException
oLog.Add(ex.Message, "SystemException", "mregulatorAddin.vb",
"oMailItem_Open")
End Try
End Sub

Kenny October 15th 07 10:55 AM

open event problem
 
It should come from my inspector, because when my open event is working my
newinspector event is called just before and when my open event is not
working, my newinspector event is not called before too. here is my inspector
event:

Private Sub m_olInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector) Handles oInspectors.NewInspector

sToString = ""
sCCString = ""
sCCiString = ""
sTopicSelected = ""

Try
oInspector = CType(Inspector, Outlook.InspectorClass)

If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
oMailItem = CType(Inspector.CurrentItem, Outlook.MailItem)
If (oMailItem.SenderEmailAddress "") Then
'Gestion du DND
If (Not IsNothing(oMailItem.Categories) And Not
oMailItem.Categories = "") Then
Dim missing As Object =
System.Reflection.Missing.Value
Dim commandBar As Office.CommandBar =
oInspector.CommandBars.Add("mregulatorCB", Office.MsoBarPosition.msoBarTop,
missing, True)
'ajout d'un bouton a la barre
oButton =
commandBar.Controls.Add(Office.MsoControlType.msoC ontrolButton, missing,
missing, missing, missing)
commandBar.Visible = True
'définition du style de bouton: contenant du texte
oButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption
'définition du texte
oButton.Caption =
Langue.GetTranslation("mregulatorAddin.vb", "txtUnsuscribeButton")
oButton.Picture =
ConvertImage.Convert(My.Resources.Disturb)
'Else
' Try
'
oInspector.CommandBars.Item("mregulatorCB").Delete ()
' Catch ex As Exception
' oLog.Add(ex.Message, "Exception",
"mregulatorAddin.vb", "m_olInspectors_NewInspector")
' End Try
End If
Else

End If
Else
sTopicSelected = ""
End If
Catch ex As SystemException
oLog.Add(ex.Message, "SystemException", "mregulatorAddin.vb",
"m_olInspectors_NewInspector")
End Try
End Sub

Thank you for helping me

Ken Slovak - [MVP - Outlook] October 15th 07 03:22 PM

open event problem
 
Are you keeping alive your NewInspector event handler? That should fire no
matter what type of Inspector is opened unless it goes out of scope.

You really should not use NewInspector for anything other than testing
CurrentItem.Class or CurrentItem.MessageClass. No other properties of the
Inspector or its CurrentItem are guaranteed to be valid or available in that
event handler, it's a weak object reference. You should do anything else in
the first Activate event fired by the Inspector.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Kenny" wrote in message
...
It should come from my inspector, because when my open event is working my
newinspector event is called just before and when my open event is not
working, my newinspector event is not called before too. here is my
inspector
event:

Private Sub m_olInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector) Handles oInspectors.NewInspector

sToString = ""
sCCString = ""
sCCiString = ""
sTopicSelected = ""

Try
oInspector = CType(Inspector, Outlook.InspectorClass)

If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
oMailItem = CType(Inspector.CurrentItem, Outlook.MailItem)
If (oMailItem.SenderEmailAddress "") Then
'Gestion du DND
If (Not IsNothing(oMailItem.Categories) And Not
oMailItem.Categories = "") Then
Dim missing As Object =
System.Reflection.Missing.Value
Dim commandBar As Office.CommandBar =
oInspector.CommandBars.Add("mregulatorCB",
Office.MsoBarPosition.msoBarTop,
missing, True)
'ajout d'un bouton a la barre
oButton =
commandBar.Controls.Add(Office.MsoControlType.msoC ontrolButton, missing,
missing, missing, missing)
commandBar.Visible = True
'définition du style de bouton: contenant du texte
oButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption
'définition du texte
oButton.Caption =
Langue.GetTranslation("mregulatorAddin.vb", "txtUnsuscribeButton")
oButton.Picture =
ConvertImage.Convert(My.Resources.Disturb)
'Else
' Try
'
oInspector.CommandBars.Item("mregulatorCB").Delete ()
' Catch ex As Exception
' oLog.Add(ex.Message, "Exception",
"mregulatorAddin.vb", "m_olInspectors_NewInspector")
' End Try
End If
Else

End If
Else
sTopicSelected = ""
End If
Catch ex As SystemException
oLog.Add(ex.Message, "SystemException", "mregulatorAddin.vb",
"m_olInspectors_NewInspector")
End Try
End Sub

Thank you for helping me



Kenny October 15th 07 03:44 PM

open event problem
 
I keep alive the new inspector, and I just testing the currentitem.

The problem I have is kind of wired, like I said I keep opening mail and
it's working but after 3 or 4 times it's not working anymore and to
reactivate it I have to open twice the mail and then the open event is
working again, that why I have shown my open event code and my inspector, I
miss something but I don't know what, I really need help on this.
Here is what I want:

I need to get the mailitem object when it's open, and that what it is doing
but not working good, I need that because I need to know when a mail is open,
reply, etc.



Ken Slovak - [MVP - Outlook] October 15th 07 04:02 PM

open event problem
 
If your NewInspector event handler isn't being fired then it's going out of
scope or you have errors in your code that is terminating your application.
That's about all I can say.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Kenny" wrote in message
...
I keep alive the new inspector, and I just testing the currentitem.

The problem I have is kind of wired, like I said I keep opening mail and
it's working but after 3 or 4 times it's not working anymore and to
reactivate it I have to open twice the mail and then the open event is
working again, that why I have shown my open event code and my inspector,
I
miss something but I don't know what, I really need help on this.
Here is what I want:

I need to get the mailitem object when it's open, and that what it is
doing
but not working good, I need that because I need to know when a mail is
open,
reply, etc.




Kenny October 15th 07 04:19 PM

open event problem
 
If it's out of scope what could I do for that?

What do you need to know for helping me I really need to find out.

If I have an error that would be fine for me but that is not the case, it's
like sometime the inspector just ignore that I'm doing an action on the mail
because when that happening outlook ask me for save the mail, and not for the
other because I parameted this already.

I have probably this error rely to this maybe it's that when I click on "new
mail" after that all icon of new mail won't change anymore, and their status
are read and not unread, that are my two big issues I have and I don't find
any explanation.

I really need help

Thank you

Ken Slovak - [MVP - Outlook] October 15th 07 08:25 PM

open event problem
 
What causes an object or event to go out of scope is if it isn't declared at
a class module level but at a procedure level. Once the procedure ends the
object is out of scope. If you declare an Inspector object at the Connection
class or Startup class or whatever class level it won't go out of scope
until the class does.

If you are trying to handle more than one open item at a time you can look
at the templates I have for Outlook 2007 in VSTO 2005 SE and shared addins
in both C# and VB.NET at
http://www.slovaktech.com/outlook_2007_templates.htm. If you are using a
different version of Outlook you can look for Inspector wrapper examples at
www.outlookcode.com for samples of how to correctly handle things.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Kenny" wrote in message
...
If it's out of scope what could I do for that?

What do you need to know for helping me I really need to find out.

If I have an error that would be fine for me but that is not the case,
it's
like sometime the inspector just ignore that I'm doing an action on the
mail
because when that happening outlook ask me for save the mail, and not for
the
other because I parameted this already.

I have probably this error rely to this maybe it's that when I click on
"new
mail" after that all icon of new mail won't change anymore, and their
status
are read and not unread, that are my two big issues I have and I don't
find
any explanation.

I really need help

Thank you




All times are GMT +1. The time now is 02:46 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com