The Table object does not have a property count
. Instead, it has the method GetRowCount
. But that comes with the warning that it’s not reliable and may return an approximate count and yield an error.
Does anyone here know what’s different about the structure of a Table object that prevents VBA from knowing its count?
>Solution :
The GetRowCount
method corresponds to the IMAPITable::GetRowCount method which explains possible reasons like memory constraints and etc. You may find the following description helpful:
Use
GetRowCount
to find out how many rows a table holds before making a call to theIMAPITable::QueryRows
method to retrieve the data. If there are less than twenty rows in the table, it is safe to callQueryPosition
to retrieve the whole table. If there are more than twenty rows in the table, consider making multiple calls toQueryPosition
and limit the number of rows retrieved in each call.
Some tables do not support GetRowCount and return
MAPI_E_NO_SUPPORT
. IfGetRowCount
is not supported, an alternative might be to callIMAPITable::QueryPosition
. With the results fromQueryPosition
, you can determine the relationship between the current row and last row.
When
GetRowCount
returns MAPI_E_BUSY because it is temporarily unable to retrieve a row count, call theIMAPITable::WaitForCompletion
method. WhenWaitForCompletion
returns, retry the call toGetRowCount
. Another way to detect whether an asynchronous operation is in progress is to call theIMAPITable::GetStatus
method and check the contents of thelpulTableState
parameter.
In Extended MAPI (a low-level API on which Outlook is based on) you can specify how many rows you would like to get using the IMAPITable::QueryRows method.