VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Recordset to Flexgrid in 1 Line!

by Anthony Loera (7 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 24th August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Recordset to Flexgrid in 1 Line!

Rate Recordset to Flexgrid in 1 Line!



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

Download this snippet    Add to My Saved Code

Recordset to Flexgrid in 1 Line! Comments

No comments have been posted about Recordset to Flexgrid in 1 Line!. Why not be the first to post a comment about Recordset to Flexgrid in 1 Line!.

Post your comment

Subject:
Message:
0/1000 characters