After
the Cellset object is open, you can display the results of the MDX
query. The following Visual Basic code shows how this task is done.
The sample code prints the data to the Visual Basic Immediate window
by calling Debug.Print.
' Print the cellset axis structure and count the number of cells.
Dim cCells As Long
Dim obAxis As ADOMD.Axis
Dim obPosition As ADOMD.Position
Dim obMember As ADOMD.Member
cCells = 1
For Each obAxis In obCellset.Axes
Debug.Print obAxis.Name & ", cells on axis: " & obAxis.Positions.Count
cCells = cCells * obAxis.Positions.Count
For Each obPosition In obAxis.Positions
For Each obMember In obPosition.Members
Debug.Print vbTab & obMember.Name & ": " & obMember.Caption
Next
Next
Next
' Print the slicer axis structure.
Debug.Print vbNewLine & "Filter/Slicer Axis:"
For Each obPosition In obCellset.FilterAxis.Positions
For Each obMember In obPosition.Members
Debug.Print vbTab & obMember.Name & ": " & obMember.Caption
Next
Next
Debug.Print ""
If cCells = 1 Then
Debug.Print "1 cell returned." & vbNewLine
Else
Debug.Print cCells & " cells returned." & vbNewLine
End If
' Print the cell values by ordinal.
Dim i As Long, j As Long
Dim obCell As ADOMD.Cell
Dim strPositions As String
For i = 0 To cCells - 1
Set obCell = obCellset(i)
strPositions = "Cell " & i & " "
' Print the position array for this cell.
' (Example: Cell 0 would be Cell(0,0,0) in a 3-d array).
strPositions = strPositions & "("
For j = 0 To obCell.Positions.Count - 1
If j > 0 Then strPositions = strPositions & ", "
strPositions = strPositions & obCell.Positions(j).Ordinal
Next
strPositions = strPositions & "): "
' Retrieve the cell value and check for NULL.
If IsNull(obCell.value) Then
strPositions = strPositions & "-null-"
Else
strPositions = strPositions & obCell.value
End If
Debug.Print strPositions
Next
' Clean up and exit.
obCellset.Close
Set obCellset = Nothing
Set obCell = Nothing
Set obAxis = Nothing
Set obPosition = Nothing
Set obMember = Nothing