Article ID: 194653
Article Last Modified on 3/14/2005
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rsVar As Variant
Dim i As Integer
cn.Open "Testing" '<-- Your DSN
rs.Open "select * from Cies", cn, adOpenStatic, adLockOptimistic
rs.MoveLast
rs.MoveFirst
' Assuming that rs is your ADO recordset
MSHFlexGrid1.Rows = rs.RecordCount + 1
rsVar = rs.GetString(adClipString, rs.RecordCount)
MSHFlexGrid1.Cols = rs.Fields.Count
' Set column names in the grid
For i = 0 To rs.Fields.Count - 1
MSHFlexGrid1.TextMatrix(0, i) = rs.Fields(i).Name
Next
MSHFlexGrid1.Row = 1
MSHFlexGrid1.Col = 0
' Set range of cells in the grid
MSHFlexGrid1.RowSel = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.ColSel = MSHFlexGrid1.Cols - 1
MSHFlexGrid1.Clip = rsVar
' Reset the grid's selected range of cells
MSHFlexGrid1.RowSel = MSHFlexGrid1.Row
MSHFlexGrid1.ColSel = MSHFlexGrid1.Col
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Name Data Type (SQL Server) Data Type(Access)
------------------------------------------------------------------
PartID Integer Integer
PartName VarChar (10) Text (10)
Control Name Caption
-------------------------------------------------------------------
CommandButton Command1 Using ADO Recordset
CommandButton Command2 Using ADODC
CommandButton Command3 Free MSHFlexGrid
MSHFlexGrid MSHFlexGrid1 Testing MSHFlexGrid Display
ADODC Adodc1
Option Explicit
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Testing" '<-- Your DSN
rs.Open "select * from Test", cn, adOpenStatic, adLockOptimistic
rs.MoveLast
' Check the number records in your ADO recordset
' The RecordCount property of the ADO recordset reflects the
' actual number of records
Debug.Print "ADO recordset record-count: " & vbTab & _
rs.RecordCount
Form1.Caption = "Loading grid... please wait..."
Set MSHFlexGrid1.Recordset = rs
' Check the number of rows that the Hierarchical FlexGrid
' contains The RecordCount property of the Hierarchical
' FlexGrid also reflects the actual number of records
Debug.Print "MSHFlexGrid1 Recordset record-count: " & vbTab & _
MSHFlexGrid1.Recordset.RecordCount
Form1.Caption = "MSHFlexGrid Display Sample"
' Free resources
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Private Sub Command2_Click()
Form1.Caption = "Loading data... please wait..."
' Set the Grid's source to be ADODC
Set MSHFlexGrid1.DataSource = Adodc1
' Check the number of records in ADODC recordset
Debug.Print "ADO data control record-count: " & vbTab & _
Adodc1.Recordset.RecordCount
Form1.Caption = "MSHFlexGrid Display Sample"
End Sub
Private Sub Command3_Click()
MSHFlexGrid1.Clear
Form1.Caption = "Grid is clear now..."
End Sub
Keywords: kbbug kbfix kbvs600sp3fix KB194653