Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Interop / October 2006

Tip: Looking for answers? Try searching our database.

Problem with CommandBarComboBox Change Event (Event fires only once)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
M. Khalid Farooq - 19 Oct 2006 13:04 GMT
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
Ken Slovak - [MVP - Outlook] - 19 Oct 2006 14:33 GMT
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.

Signature

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
M. Khalid Farooq - 19 Oct 2006 17:59 GMT
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

   "M. Khalid Farooq" <khalid@comsdev.com> wrote in message news:ezHXaY38GHA.940@TK2MSFTNGP03.phx.gbl...
   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
Ken Slovak - [MVP - Outlook] - 20 Oct 2006 14:41 GMT
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.

Signature

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
M. Khalid Farooq - 20 Oct 2006 15:41 GMT
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

   "M. Khalid Farooq" <khalid@comsdev.com> wrote in message news:us6eY958GHA.4964@TK2MSFTNGP02.phx.gbl...
   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
Ken Slovak - [MVP - Outlook] - 21 Oct 2006 20:00 GMT
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.

Signature

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.
M. Khalid Farooq - 23 Oct 2006 09:44 GMT
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

   "M. Khalid Farooq" <khalid@comsdev.com.pk> wrote in message news:ewG28XF9GHA.1012@TK2MSFTNGP05.phx.gbl...
   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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.