0

In the following code:

Sub test(oEmailFolder As Folder, sFilter as String)

Dim oOutlookTable As Outlook.Table

Set oOutlookTable = oEmailFolder.GetTable(sFilter)
oOutlookTable.Columns.Add ("Class")

End Sub

the line with the call to Add gives the error:

  • Run-time error '-2147024809 (80070057)': The property "Class" does not support this operation.

This is the same error I got when I previously tried to add object or computed properties.

According to Unsupported Properties in a Table Object or Table Filter, there are restrictions on adding binary properties, body properties, computed properties, multi-values properties, or object properties. MailItem.Class is a numeric constant that does not appear to be any of those five kinds of properties. Why am I getting that error?

NewSites
  • 1,402
  • 2
  • 11
  • 26

2 Answers2

0

Use MessageClass instead, which corresponds to the PR_MESSAGE_CLASS property in MAPI.

Class is an Outlook Object Model specific property exposed by all OOM objects (even if they are not MAPI based), it is similar to PR_OBJECT_TYPE in MAPI, but not at all the same.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I'm already collecting `MessageClass` and I want to collect `Class` too. It's a property of `MailItem` and, as far as I can tell, is not one of the kinds of properties that is unsupported in tables. So, is there a reason I can't add a column for it? – NewSites May 29 '23 at 23:59
  • Yes, I outlined the reason above - it is not a MAPI based property. but something furnished by Outlook itself. You can only specify something exposed by the underlying store provider - if you cannot see the value in the GetProps tabs of the IMessage window in OutlookSpy, you cannot add it. – Dmitry Streblechenko May 30 '23 at 03:06
  • And using `MessageClass` is easy enough - if `MessageClass` starts with `"IPM.Note"`, it is `43 (OlObjectClass.olMail)`, if it starts with `"IPM.Appointment"` - you have `26 (OlObjectClass.olAppointment)`, etc. – Dmitry Streblechenko May 30 '23 at 03:08
  • The page on unsupported properties in tables doesn't say anything about a requirement that a property be MAPI-based. Is that requirement stated somewhere? – NewSites May 30 '23 at 06:27
  • The items in my folders with `DefaultItemType = olMailItem` have nine values of `MessageClass`: `IPM.Appointment`, `IPM.Note`, `IPM.Post.Rss`, `IPM.Schedule.Meeting.Canceled`, `IPM.Schedule.Meeting.Request`, `IPM.Schedule.Meeting.Resp.Neg`, `IPM.Schedule.Meeting.Resp.Pos`, `IPM.Schedule.Meeting.Resp.Tent`, and `REPORT.IPM.Note.NDR`. Is there somewhere to look up the corresponding values of `Class`? – NewSites May 30 '23 at 06:31
  • sigh... yes, the page does not say anything about that. Is my word enough? – Dmitry Streblechenko May 30 '23 at 06:53
  • DefaultItemType means nothing. It is the default item class of a folder, just a hint, nothing more. What you are requesting from a table, is the class of each item in the folder contents table, and that directly corresponds to MessageClass. – Dmitry Streblechenko May 30 '23 at 06:56
  • As for whether your word is enough, it may have to be if the documentation is wrong. Are you telling me to add to my notes on that page that another category of properties that is not supported in tables is properties that do not have a corresponding MAPI property? – NewSites May 30 '23 at 07:16
  • If the documentation page had everything you needed, you wouldn't need Stack Overflow, right? The page does not specifically mention the `Class` property, but it does say *Computed properties, such as AutoResolvedWinner and BodyFormat.*. – Dmitry Streblechenko May 30 '23 at 15:29
  • Is `Class` a computed property? – NewSites May 30 '23 at 15:37
  • Yes. From my answer above: *Class is an Outlook Object Model specific property exposed by all OOM objects (even if they are not MAPI based), it is similar to PR_OBJECT_TYPE in MAPI, but not at all the same.* – Dmitry Streblechenko May 30 '23 at 15:40
  • (a) I don't understand how the part of your question that you just quoted means that `Class` is computed. If you can refer me to something to read that explains that, please do. (b) If `Class` is computed, then the documentation is not wrong, and I wish I knew how to know what properties are computed. – NewSites May 30 '23 at 16:02
  • As I mentioned above, if you see the corresponding MAPI property in OutlookSpy or MFCMAPI, it is **not** computed. Everything else is. Now, there are also MAPI computed properties, but those simply cannot be updated, which does not apply in your case. – Dmitry Streblechenko May 30 '23 at 16:14
  • OutlookSpy is great, but is there not a way to know if a property is computed without referring to it or to MFCMAPI? Is there no information from MS that indicates whether a property is computed or not? – NewSites May 30 '23 at 17:33
  • Not really. Checking whether a particular property is read-only in OOM won't help either. – Dmitry Streblechenko May 30 '23 at 18:26
0

Use a string property instead, try the MailItem.MessageClass property:

If (oOutlookFolder.DefaultItemType = olMailItem) Then
    Set oOutlookTable = oOutlookFolder.GetTable(sFilter)
    oOutlookTable.Columns.Add ("MessageClass")
    ...
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • `MessageClass` doesn't have to be added because it's included in every table by default. And unless I'm mistaken, it's not equivalent to `Class`, so I want to collect both. – NewSites May 29 '23 at 23:54
  • You need to build connections in the code without putting the `Class` property to the table. See [Item Types and Message Classes](https://learn.microsoft.com/en-us/office/vba/outlook/concepts/forms/item-types-and-message-classes) and [OlObjectClass enumeration](https://learn.microsoft.com/en-us/office/vba/api/outlook.olobjectclass) – Eugene Astafiev May 30 '23 at 06:15