ipetrik
ipetrik

Reputation: 2044

Populate Outlook form Subject from user-defined fields

I designed the form below:
enter image description here

I would like the Subject to be automatically populated with the value of "[Machine] - [TAT]" as soon as those values are filled. I don't know how to access the values of these fields, the syntax for the value change listeners, nor where I should be putting this code.

When I click "Visual Basic", all I see is this:

enter image description here

It seems that this is only programmatic access to the Application, not the form.

How do I programmatically access the form that I designed?

Upvotes: 0

Views: 915

Answers (1)

Eric Legault
Eric Legault

Reputation: 5834

Legacy form customizations require using VBScript for the "code behind", primarily for interactions with your custom UI. However, VBA macros are used independent of custom forms to work with Outlook items and data. If the business logic for your custom form requires working with the active MailItem, then VBScript is what you need to use.

For your scenario, you need to trap changes to the values of your custom controls. The best practice is to create custom fields in the Outlook item and map those fields to the controls. If you don't, you will only be able to write validation formulas in the designer for those controls, and you cannot trap value changes (odd, I know). Luckily custom fields fire the Item_CustomPropertyChange event, which is exactly what you need.

For more info, see:

Manipulating Controls Programmatically MailItem.CustomPropertyChange Event

Upvotes: 1

Related Questions