Cellset Example

The following code demonstrates how to open a Cellset, print captions of the Members for each position and print the formatted value of the Cell. This code assumes there is a Data Source named Bobs Video Store on the OLAP server.

Dim cat     As New ADOMD.Catalog
Dim cst     As New ADOMD.Cellset
Dim axs     As ADOMD.Axis
Dim i       As Integer
Dim j       As Integer
cat.ActiveConnection = "Data Source=Bobs Video Store;Provider=msolap;"
cst.Source = "SELECT [Product Category].MEMBERS ON ROWS, _
                     [Store State].MEMBERS ON COLUMNS _
              FROM   [Bobs Video Store] _
              WHERE  ([Quantity])"
Set cst.ActiveConnection = cat.ActiveConnection
cst.Open
For i = 0 To cst.Axes(0).Positions.Count - 1
    Debug.Print cst.Axes(0).Positions(i).Members(0).Caption & " ";
    Set axs = cst.Axes(1)
    For j = 0 To axs.Positions.Count - 1
        Debug.Print "     " & axs.Positions(j).Members(0).Caption & _
          " " & cst(i, j).FormattedValue
    Next
Next