Adding Columns to a Table Object
This topic describes how to add columns to a Table object.
To obtain an initial Table object, use Folder.GetTable or Search.GetTable. The returned Table object always contains a default set of properties depending on the folder type of the parent folder. If you want to change the columns in a Table, start with the Table object returned from a prior GetTable call. Use Table.Columns to obtain the Columns object, and call Columns.Add, Columns.Remove, or Columns.RemoveAll. As a result of the call on the Columns object, the parent Table object is updated.
Note Each of these calls on the Columns object adjusts the columns in the parent Table. The rows in the Table however remain the same as before the call. You don't call GetTable subsequently to obtain an updated Table. GetTable always returns a Table with the default set of columns for that folder type.
Since a folder can contain heterogeneous items (for example, the Deleted Items folder), you can use Columns.Add to add columns that don't apply to all rows in that Table. In such cases, Row.Item would return an error indicating that an object could not be found for the row at the specific column. Consequently, before you access other column values in a Table, you should first check for the MessageClass of a row (by calling Row.Item("MessageClass")
) to determine which columns in the Table apply to that row.
Note Since the Item method is the default method for the Row object, Row.Item("MessageClass")
is equivalent to Row("MessageClass")
.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.