Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a FlexGrid or Sheridan DataGrid

DataGrid

Populate a FlexGrid or Sheridan DataGrid

by  Bubbler  Posted    (Edited  )
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

Exit Function
ErrorHandler:

LoadRecordSetIntoGrid = False
End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top