Problem with CommandBarComboBox Change Event (Event fires only once)

  • Thread starter Thread starter M. Khalid Farooq
  • Start date Start date
M

M. Khalid Farooq

Hi,

I am having a problem with CommandBarComboBox's Change Event. I have added a toolbar in New Email Item Inspector. It shows few CommandBarButton and one Combo box. On ComboBox Change event, I have to set a custom HTML Contents for the current mail item body.

My problem is that everything works perfect for the first time. I got Combo Box. On Selecting an item I got body changed to what I desire. However it doesn't fire Change Event on next selection. I want to make it change body whenever user changes selection in the Combo Box. Here is the Code as how I added this ComboBox,

Private Sub templateComboBox_Change(ByVal Ctrl As Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

Try

Me.m_olMailItem.HTMLBody = "<html><body><b>" + Ctrl.Text + "</b></body></html>"

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub


There comes no exception and it works fine for first selection. On second or later selections there is neither any change in the body nor any exception came out. Please help me to understand whats wrong with it.

Thanks,

Khalid
 
Make sure your references are staying alive and aren't being eaten by the
garbage collector. Set a module or global reference to things so they aren't
collected.




Hi,

I am having a problem with CommandBarComboBox's Change Event. I have added
a toolbar in New Email Item Inspector. It shows few CommandBarButton and one
Combo box. On ComboBox Change event, I have to set a custom HTML Contents
for the current mail item body.

My problem is that everything works perfect for the first time. I got
Combo Box. On Selecting an item I got body changed to what I desire. However
it doesn't fire Change Event on next selection. I want to make it change
body whenever user changes selection in the Combo Box. Here is the Code as
how I added this ComboBox,

Private Sub templateComboBox_Change(ByVal Ctrl As
Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

Try

Me.m_olMailItem.HTMLBody = "<html><body><b>" + Ctrl.Text +
"</b></body></html>"

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub


There comes no exception and it works fine for first selection. On second
or later selections there is neither any change in the body nor any
exception came out. Please help me to understand whats wrong with it.

Thanks,

Khalid
 
Hi Ken,

Thank you for the prompt response. I am sorry for multiple posts. It was just to get response as early as possible.

All the objects are having class level scope. I am using three CommandBarButton as well and they stay alive no matter how many times they are being called. Another interesting improvement is that I placed a simple message box prompt there and now it is being called multipled times without any problem. Please see code bellow,

Private Sub templateComboBox_Change(ByVal Ctrl As Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

MsgBox(Ctrl.Text)

End Sub


Apperantly looks like something goes wrong when I set HtmlBody of the current mailIterm object.

Please advice,

Thanks,

Khalid

Make sure your references are staying alive and aren't being eaten by the garbage collector. Set a module or global reference to things so they aren't collected.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


Hi,

I am having a problem with CommandBarComboBox's Change Event. I have added a toolbar in New Email Item Inspector. It shows few CommandBarButton and one Combo box. On ComboBox Change event, I have to set a custom HTML Contents for the current mail item body.

My problem is that everything works perfect for the first time. I got Combo Box. On Selecting an item I got body changed to what I desire. However it doesn't fire Change Event on next selection. I want to make it change body whenever user changes selection in the Combo Box. Here is the Code as how I added this ComboBox,

Private Sub templateComboBox_Change(ByVal Ctrl As Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

Try

Me.m_olMailItem.HTMLBody = "<html><body><b>" + Ctrl.Text + "</b></body></html>"

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub


There comes no exception and it works fine for first selection. On second or later selections there is neither any change in the body nor any exception came out. Please help me to understand whats wrong with it.

Thanks,

Khalid
 
Just displaying a message box isn't accessing the body or htmlbody of
course. I have no idea why it's failing if you do that. Is there any other
code in that event handler that you're not showing. The code as shown
doesn't show anything that should cause problems I don't think.




Hi Ken,

Thank you for the prompt response. I am sorry for multiple posts. It was
just to get response as early as possible.

All the objects are having class level scope. I am using three
CommandBarButton as well and they stay alive no matter how many times they
are being called. Another interesting improvement is that I placed a simple
message box prompt there and now it is being called multipled times without
any problem. Please see code bellow,

Private Sub templateComboBox_Change(ByVal Ctrl As
Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

MsgBox(Ctrl.Text)

End Sub


Apperantly looks like something goes wrong when I set HtmlBody of the
current mailIterm object.

Please advice,

Thanks,

Khalid
 
Hi Ken,

Thank you for replying my posts. I have uploaded a sample plugin at the following URL.(I was unable to post it here because it is around 400kb)

http://www.ipd.com.pk/download/MyTestOutlookAddin.zip

I created this just to explain this problem. It has a little code adding just one CommandBarComboBox and capturing its Change Event. I have also commented message box so you can uncomment it to see as it works fine. However when I set something to HtmlBody of current email item, it works only for the first time. All the objects are alive and within public scope. There is no exception at all. This makes this bug very mystrious. I hope you will be able to figure out whats wrong by going through this example.

Thanks,

Khalid

BTW: I am using Visual Studio 2005 and MS Outlook 2003. Also, I am not using VSTO rather its simple Shared Addin.


Just displaying a message box isn't accessing the body or htmlbody of course. I have no idea why it's failing if you do that. Is there any other code in that event handler that you're not showing. The code as shown doesn't show anything that should cause problems I don't think.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


Hi Ken,

Thank you for the prompt response. I am sorry for multiple posts. It was just to get response as early as possible.

All the objects are having class level scope. I am using three CommandBarButton as well and they stay alive no matter how many times they are being called. Another interesting improvement is that I placed a simple message box prompt there and now it is being called multipled times without any problem. Please see code bellow,

Private Sub templateComboBox_Change(ByVal Ctrl As Microsoft.Office.Core.CommandBarComboBox) Handles templateComboBox.Change

MsgBox(Ctrl.Text)

End Sub


Apperantly looks like something goes wrong when I set HtmlBody of the current mailIterm object.

Please advice,

Thanks,

Khalid
 
I'm not going to be able to download your code and install and test it.
That's something I don't have time for.

In the event handler for the click event is there any other code you're not
showing, or is that it?

I'd suggest opening a support incident with MS support about this, they'll
be able to analyze your addin and see what's going wrong. This is a peer to
peer forum and not really an appropriate place for extensive program
analysis.




Hi Ken,

Thank you for replying my posts. I have uploaded a sample plugin at the
following URL.(I was unable to post it here because it is around 400kb)

http://www.ipd.com.pk/download/MyTestOutlookAddin.zip

I created this just to explain this problem. It has a little code adding
just one CommandBarComboBox and capturing its Change Event. I have also
commented message box so you can uncomment it to see as it works fine.
However when I set something to HtmlBody of current email item, it works
only for the first time. All the objects are alive and within public scope.
There is no exception at all. This makes this bug very mystrious. I hope you
will be able to figure out whats wrong by going through this example.

Thanks,

Khalid

BTW: I am using Visual Studio 2005 and MS Outlook 2003. Also, I am not
using VSTO rather its simple Shared Addin.
 
Hi Ken,

Thanks for your reply. Eventhough the code I sent you takes a few minutes only to understand as I did nothing but created a CommandBar, added a ComboBox and on Combo Box's Change Event set the body to a html string yet I understand your position. I really appreciate your help. Thanks for replying my posts here.

Just for those that might be interested in this thread. I have found this as a BUG in Outlook. If you set HtmlBody of an opened MailItem, it will no longer keep the reference of your Combo Box. Hence I did a trick and its working for me now. I just refreshed the reference by going into CommandBar with Find property and reterived the reference to this already present Combo Box. Its working now. I have called this function as Reset Reference. Here is the code for anyone who might be interested in this,

Private Sub resetComboReference()
Dim cbr As CommandBar

For Each cbr In objInspector.CommandBars

If cbr.Name = "My Toolbar" Then

Try

templateComboBox = CType(cbr.FindControl(Tag:="Template"), CommandBarComboBox)

' It forgets its selected item so I have stored it in a global String Variable. Here I am restoring it back.

If strSelectedTemplate <> "" Then

templateComboBox.Text = strSelectedTemplate

End If

Catch ex As SystemException

msgbox(ex.Message)

End Try

End If

Next



I hope it will help if someone faced similar situation.

Thanks,

Khalid


I'm not going to be able to download your code and install and test it. That's something I don't have time for.

In the event handler for the click event is there any other code you're not showing, or is that it?

I'd suggest opening a support incident with MS support about this, they'll be able to analyze your addin and see what's going wrong. This is a peer to peer forum and not really an appropriate place for extensive program analysis.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


Hi Ken,

Thank you for replying my posts. I have uploaded a sample plugin at the following URL.(I was unable to post it here because it is around 400kb)

http://www.ipd.com.pk/download/MyTestOutlookAddin.zip

I created this just to explain this problem. It has a little code adding just one CommandBarComboBox and capturing its Change Event. I have also commented message box so you can uncomment it to see as it works fine. However when I set something to HtmlBody of current email item, it works only for the first time. All the objects are alive and within public scope. There is no exception at all. This makes this bug very mystrious. I hope you will be able to figure out whats wrong by going through this example.

Thanks,

Khalid

BTW: I am using Visual Studio 2005 and MS Outlook 2003. Also, I am not using VSTO rather its simple Shared Addin.
 
Back
Top