This example demonstrates how to Populate a FlexGrid or Sheridan DataGrid:
Public Function LoadRecordSetIntoGrid(ctlGrid As MSFlexGrid, _
rs As ADODB.Recordset) As Boolean
Dim sTmp As String
Dim vArr As Variant
Dim i As Integer
On Error GoTo ErrorHandler
'first we have to clear the grid from previous query results
'**** remove existing grid rows
ctlGrid.Rows = 2
ctlGrid.AddItem ""
ctlGrid.RemoveItem 1
If Not rs.EOF And Not rs.BOF Then
'get the recordset into a string delimiting the fields
'with a tab character and the records with a semicolon
'replace nulls with a space
sTmp = rs.GetString(adClipString, , Chr(9), ";", " ")
'split the string into an array of individual records
vArr = Split(sTmp, ";")
'now add the records to the grid
For i = 0 To UBound(vArr) - 1
ctlGrid.AddItem vArr(i)
Next
'set the return value
LoadRecordSetIntoGrid = True
Else
LoadRecordSetIntoGrid = False
Exit Function
End If
'remove empty rows
If ctlGrid.Rows > 2 Then
On Error Resume Next 'get over removing a single record
For i = 1 To ctlGrid.Rows - 1
If ctlGrid.TextMatrix(i, 1) = "" Then
ctlGrid.RemoveItem i
Else
Exit For
End If
Next
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.