Setting combobox properties from Outlook 2007 Add-in

P

paresh

Hi,

Could any one please help me with setting below properties for combobox
created on Outlook toolbar using Outlook 2007 Add-in. Please refer attached
initial code I wrote to create combobox in my Outlook command bar.

Could you tell me how to achieve below items:

1. When I select any "test" items from combobox the myComboBox_Click()
doesn't get called. Could you tell me what is wrong in the code?

2. How to add "FaceID" along with msoComboLabel properties? Basically I
want to have picture with the label name. I cannot use ".FaceID" as it gives
compile time error "method or data type not found". Could you help me on this.

Any help would be much appreciated.

My code:
' I have written below code in Connect.Dsr
' For your information, the similar methods work for CommandBarButton

Private WithEvents myComboBox As Office.CommandBarComboBox

Private Sub myComboBox_Click()
MsgBox "Combobox selection change event"
End Sub

Set mylComboBox = myCommandBar.Controls.Add(msoControlComboBox)
With myComboBox
.OnAction = "myComboBox_Click"
.Style = msoComboLabel
.AddItem "test1"
.AddItem "test2"
.AddItem "test3"
.Visible = True
End With
End If

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

If you are going to write Outlook and Office addins you really need to
become familiar with the object models you are working with. Try looking in
the Object Browser sometime.

There is no Click() event for a CommandBarComboBox control, and no support
for images. You can only do what the controls you are working with support.
 
P

paresh

Thanks a lot Ken. That was the precise answer. I looked into Object browser
and then only I have posted this question but now I realized that I looked in
VB Combobox and not CommandBarComboBox.

I am curious then is there any way to create VB combobox on Outlook toolbar?
I want to handle click event and need some small gif images inside that.

If it is possible in any aspects, I would be fine.

Thanks for being there.
Paresh
 
P

paresh

The other thing is below method doesn't work either. It gives compile time
error "The procedure declaration doesnt match description of event or
prcedure having the same name". Could you please tell me what is wrong here?

Sub myCombobox_Change(Ctrl As Office.CommandBarComboBox)
MsgBox "Combobox selection changed"
End Sub

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

Normally that's not possible. Add-In Express lets you use controls that are
managed code controls such as a combo, but only if you use their framework.
They are using Win32 API hacks to put things where they want them and then
using message hooks to listen for events on those controls. Otherwise you
just have to use what you are given.
 
K

Ken Slovak - [MVP - Outlook]

The event handler signature looks OK, but that should be automatic in VB6 if
you declared myCombobox WithEvents.
 
P

paresh

Ken, please refer my complete code given below. It gives the same error.

Private WithEvents myComboBox As Office.CommandBarComboBox

Sub myComboBox_Change(Ctrl As Office.CommandBarComboBox)
MsgBox "Combobox selection changed"
End Sub

Set myComboBox myCommandBar.Controls.Add(msoControlComboBox)
With myComboBox
.BeginGroup = True
.Caption = "Test"
.Enabled = True
.OnAction = "myComboBox_Change"
.Style = msoComboLabel
.AddItem "Test1"
.AddItem "Test2"
.AddItem "Test3"
.Visible = True
End With

When I change myComboBox_Change event to just Change event, it doesnt give
that error but doesn't work either. When I select the "Test1" from combobox,
it doest print my message box.

Sub Change(Ctrl As Office.CommandBarComboBox)
MsgBox "Combobox selection changed"
End Sub

Could you please tell me what could be wrong here?

Thanks, Paresh
 
P

paresh

The below worked.

Private Sub myComboBox_Change(ByVal Ctrl As Office.CommandBarComboBox)

Please note the ByVal word.

Thanks.
 
K

Ken Slovak - [MVP - Outlook]

In VBA/VB the default is ByRef, I guess it didn't like that implicit ByRef
and wanted a ByVal. Good detective work.

I haven't used that control very often in toolbars, it's just too funky in
how it works for my taste.
 
P

paresh

Yes Ken, you are correct. I have wasted two days in that simple "ByVal" Word :)

Thanks, Paresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top