Recordset to Flexgrid in 1 Line!
Recordset to Flexgrid in 1 Line!
Rate Recordset to Flexgrid in 1 Line!
(1(1 Vote))
dim rs as adodb.recordset
rs.Open "SELECT * FROM Authors", "DSN=Pubs"
'the one liner is below
if RS2FlexGrid(MyFlexGrid, rs) = true then msgbox "Populated Flexgrid!"
set rs = nothing
End Sub
Public Function RS2FlexGrid(byval FlexGrid As Object,byval rs As Object) As Boolean
On Error GoTo ErrorHandler
If Not TypeOf FlexGrid Is MSFlexGrid Then Exit Function
If Not TypeOf rs Is ADODB.Recordset Then Exit Function
Dim i As Integer
Dim J As Integer
rs2FlexGrid = False
FlexGrid.FixedRows = 1
FlexGrid.FixedCols = 0
If Not rs.EOF Then
FlexGrid.Rows = rs.RecordCount + 1
FlexGrid.Cols = rs.Fields.Count
For i = 0 To rs.Fields.Count - 1
FlexGrid.TextMatrix(0, i) = rs.Fields(i).Name
Next
i = 1
Do While Not rs.EOF
For J = 0 To rs.Fields.Count - 1
If Not IsNull(rs.Fields(J).Value) Then
FlexGrid.TextMatrix(i, J) = _
rs.Fields(J).Value
End If
Next
i = i + 1
rs.MoveNext
Loop
End If
rs2FlexGrid = True
ErrorHandler:
Exit Function
End Function
Recordset to Flexgrid in 1 Line! Comments
No comments yet — be the first to post one!
Post a Comment