Reference fields on the Outlook email form


James C


I'm writing a C# Outlook add-in for MS Outlook 2003. The functionality I
require is to pass the contents of the "to" and "cc" fields on an email form
to a custom form (popped via a custom toolbar button).

Therefore, if a user throws a new email form, enters text into the fields,
then uses the custom toolbar to throw my email form, I need to be able to
access each control on the email form and read what the user has entered.

I have successfully added the custom toolbar and can throw my new form from
the Outlook email form, however, I don't know how to reference the "To",
"CC", "Subject" and "mail body" fields at the time my toolbar button is

I've tried doing the following in the
_CommandBarButtonEvents_ClickEventHandler event of my CommandBarButton object:


objMailItem =

MessageBox.Show("objMailItem.To = " + objMailItem.To);
MessageBox.Show("objMailItem.Subject = " + objMailItem.Subject);

//Results in objMailItem.To and objMailItem.Subject being empty string, even
//the user has amended the fields


but objMailItems .to and .subject properties only return the properties at
the time the email form was thrown, not at the time the command button was
clicked. Thus, I can't access any text entered by the user in these fields.

Any help or pointers would be really appreciated on this - it's been driving
me mad for days!

Many thanks.


Ken Slovak - [MVP - Outlook]

What do you mean by "but objMailItems .to and .subject properties only
return the properties at
the time the email form was thrown, not at the time the command button was

The button is being displayed in the Inspector window for that item? And the
Inspector is already instantiated as myInspector? If so then
myInspector.CurrentItem will return the item in that Inspector and from
there your use of the properties for Subject and To are correct.

Is objMailItem declared at any point, as in Outlook.MailItem objMailItem =
null; or something like that?

Can you step the code in the Click event and make sure that your object
variables are actually instantiated and that the properties on objMailItem
are looking correct?

No exceptions on the code?

James C

Hi Ken,

The custom toolbar is held on the eMail form (i.e. on the Inspector window
for that item). The Inspector is already instantiated as myInspector.

The Outlook.MailItem object, objMailItem is instantiated correctly and the
code compiles and executes without error. However, I think I need to be able
to reference the actual "To" textbox on the email form, as opposed to the
"To" property of objMailItem.

I'm relatively new to Outlook programming so I'm not even sure this is
possible, but what I want to be able to do is to get a reference to the eMail
form itself, look at the Controls collection, find the "To" textbox and read
the .Text property. And do all this once the button on my custom toolbar is
clicked. What I’m finding is that objMailItem.To does not display the
contents of the “To†textbox, instead displaying the property of the
objMailItem as soon as the form is opened (i.e. empty sting, as the user
hasn’t entered anything into the “To†textbox).

Simply reading the objMailItem's "To" property doesn't cut it as the value
of objMailItem.To is not up-to-date by the time the toolbar command button is

Any ideas?

Thanks again!

Ken Slovak - [MVP - Outlook]

The recipient control (the to field) just shows what the To property has as
a value. Does it make a difference if you save the item before trying to
read the values you want? Otherwise try reading the Recipients collection
and getting each recipient (although that needs a save usually also).

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