'---------------------------------------------------------------------------------------
' Procedure : FillFlexGrid
' DateTime : 26/03/02 08:40
' Purpose : Fills MSFlexGrid with values in ADODB.Recordset
' If NewGrid is set to false inRes values are added
' to existing rows
' Else old rows are deleted
' Pre-Conditions : inGrid must have 1 or 0 FixedColumns
' inGrid must have 1 or 0 FixedRows
'---------------------------------------------------------------------------------------
'
Public Sub FillFlexGrid(ByRef inGrid As MSFlexGrid, _
ByVal inRes As ADODB.Recordset, _
Optional ByVal NewGrid As Boolean = True)
'If a new grid remove old rows
'If NewGrid
If (NewGrid) Then
'If inGrid has a fixed row
If (inGrid.FixedRows = 1) Then
'Leave FixedRow
inGrid.Rows = 1
Else
'Clear all rows
inGrid.Rows = 0
End If ' (inGrid.FixedRows = 1) Then
End If ' (NewGrid)
'Make inGrid columns = number of fields in inRes
inGrid.Cols = inRes.Fields.Count
Dim thisRow As String 'To create row to add to grid
Dim i As Integer 'For loop count
'If there are records
If (Not (inRes.BOF And inRes.EOF)) Then
'Go to the first one
inRes.MoveFirst
'While not at the last one
While (Not inRes.EOF)
'If inGrid has a fixed column
If (inGrid.FixedCols = 1) Then
'Make 1st value TAB
thisRow = vbTab
End If ' (inGrid.FixedCols = 1) Then
'While fields left
For i = 0 To inRes.Fields.Count - 1
'Add field value to thisRow & TAB to move to next Column
thisRow = thisRow & inRes.Fields(i).Value & vbTab
'Next field
Next ' For i = 0 To inRes.Fields.Count - 1
'Add thisRow to inGrid
inGrid.AddItem thisRow
'Reset
i = 0
'Reset
thisRow = ""
'Next record
inRes.MoveNext
Wend ' (Not inRes.EOF)
End If ' (Not (inRes.BOF And inRes.EOF)) Then
End Sub ' FillFlexGrid