Accessing outlook form controls.

M

MeAgin

Hi all,



I want to access controls in a outlook form within a com add-in.

Please help.

Nadee
 
E

Eric Legault [MVP - Outlook]

All custom controls on a custom form can be accessed using this syntax:

Dim objControl as Object

Set objControl =
myMailItem.GetInspector.ModifiedFormPages("P.2").Controls("MyTextBox")

You don't need an item object if you already have an Inspector object. You
also need to call the name of the page with the ModifiedFormPages method, and
the control name in the Controls collection.
 
M

MeAgin

Hi Eric,

Thanks for the info.
In my VB.NET code initially I tried to get the object to a variable with the
ListBox type not Object type as mentioned. That was giving an error and when
I defined the variable as an Object it is working.
When I checked the type is shown that the type of this object is
"System.__ComObject" even it is a ListBox in the mail form.
Now I want to add some items to the ListBox and when I try to add items to
the Items collection like,

oControl.Items.Add("Item1")

It doesn't add and giving and error.
"Public member 'Items' on type 'Control' not found."

Then I tried to cast the object to a ListBox as
oListBox = CType(oControl, ListBox)
But it failec with the message,

"Unable to cast COM object of type 'System.__ComObject' to class type
'System.Windows.Forms.ListBox'. Instances of types that represent COM
components cannot be cast to types that do not represent COM components;
however they can be cast to interfaces as long as the underlying COM
component supports QueryInterface calls for the IID of the interface."

I understand the message but how can I cast the object as an interface. My
requiremnent is to add some items to a list box in a mail form from my com
add-in.

Thanks.
Nadee
 
K

Ken Slovak - [MVP - Outlook]

You need to cast it to a control in the MS Forms 2.0 library, not to a
Windows.Forms control. You should have a reference to that library so the
properties, etc. of that ListBox are available to you.

The ListBox used in Outlook form controls doesn't have an Items collection,
it has an AddItem method. All the items in the list are in the List
collection. After adding that library reference use the Object Browser to
see what's available to you for that control.
 

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