Any Other Columns in Microsoft Outlook We Can Use

Add-in Express™ Support Service
That's what is more important than anything else

Any Other Columns in Microsoft Outlook We Can Use
 
Jun Wei Ng




Posts: 18
Joined: 2019-10-01
Hi There,

Refer to the link below (Properties section),

https://docs.microsoft.com/en-us/office/vba/api/outlook.documentitem

Other than all the mentioned properties (in Outlook, they are columns) in the above link, are there any properties we can use ?

Or actually we can create our own column for DocumentItem programatically ?

Best Regards,
Jun Wei
Posted 22 Oct, 2019 21:43:23 Top
Andrei Smolin


Add-in Express team


Posts: 16678
Joined: 2006-05-11
Hello Jun,

You can create a UserProperty: 1) get the UserProperties collection object via {an Outlook item such as DocumentItem}.UserProperties, 2) add a UserProperty to the collection via newUserProperty = theUserProperties.Add(), 3) set value on the user property added: newUserProperty.Value={...}, 4) release newUserProperty and theUserProperties, 5) save the item.

For the user property to be shown in the view, you need to modify the current view or create a new one. When doing this, modify the MAPIFolder.UserDefinedProperties collection of the folder in question so that the user property is listed. Note that UserProperties.Add() provides a parameter that adds the user property to the folder (in addition to adding it to the current item)

In the Outlook Explorer UI, you modify the view in the following way:
- Click View Settings on the View tab.
- Click Columns....
- In the Select available columns from drop down, select User-defined field in folder.
- Select a user property in the Available columns list and click Add.
- Optionally, reposition the user property column in the Show these columns in this order list: use the Move Up and Move Down buttons.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 03:47:35 Top
Jun Wei Ng




Posts: 18
Joined: 2019-10-01
Hi Andrei,

I do according what you said, here is my source code:

1- Dim fld As Outlook.UserProperties
2- fld = OutlookApp.ActiveExplorer.Selection.Item(1).UserProperties (this is DocumentItem, not MailItem, tested with MailItem, no exception occurred.)
3- Dim fld2 As Outlook.UserProperty
4- fld2 = fld.Add("Column2", Outlook.OlUserPropertyType.olText)
5- fld2.Value = "abc"
6- OutlookApp.ActiveExplorer.Selection.Item(1).Save()

When it comes to the line 5, exception occurred.

What could possibly caused the exception happened ?

Best Regards,
Jun Wei
Posted 23 Oct, 2019 05:00:37 Top
Andrei Smolin


Add-in Express team


Posts: 16678
Joined: 2006-05-11
Jun Wei Ng writes:
When it comes to the line 5, exception occurred.


What exception exactly?

Jun Wei Ng writes:
2- fld = OutlookApp.ActiveExplorer.Selection.Item(1).UserProperties


I believe in your actual code you release the COM objects this code line creates.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 05:50:57 Top
Jun Wei Ng




Posts: 18
Joined: 2019-10-01
Hi Andrei,

It says "The object doesn't support this method".

But I did not release any COM objects yet.

Best Regards,
Jun Wei
Posted 23 Oct, 2019 06:03:56 Top
Andrei Smolin


Add-in Express team


Posts: 16678
Joined: 2006-05-11
Can it be that the user property is already added to that item and your code doesn't foresee this yet?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 06:20:56 Top
Jun Wei Ng




Posts: 18
Joined: 2019-10-01
Hi Andrei,

I can see the new column in add when I view in the 'View Settings'.

But the exception still occur.

Best Regards,
Jun Wei
Posted 23 Oct, 2019 06:37:31 Top
Andrei Smolin


Add-in Express team


Posts: 16678
Joined: 2006-05-11
I suppose you get an exception on the previous line: 4- fld2 = fld.Add("Column2", Outlook.OlUserPropertyType.olText)

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 06:52:11 Top
Jun Wei Ng




Posts: 18
Joined: 2019-10-01
Hi Andrei,

No, there is no exception happens in line 4, it only happens in line 5.

Could it anything wrong with my source code ?

I tried with MailItem, it has no exception at all.

But what I'm trying is DocumentItem, could you advise ?

Best Regards,
Jun Wei
Posted 23 Oct, 2019 20:39:20 Top
Andrei Smolin


Add-in Express team


Posts: 16678
Joined: 2006-05-11
Hello Jun Wei,

Does the issue occur after you turn off all other COM add-ins and restart Outlook?

Set a breakpoint on that line. In the Locals window, what is the exact type of the fld2 variable?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Oct, 2019 02:44:27 Top