Rellenar un MSFlexGrid con SQL

 

Fecha: 03/Feb/99 (29/Sep/98)
Autor: Luis Navarro < [email protected] >


Aqui te mando una funcion con el siguiente formato :

Regrid SQL,nombredelmsflexgrid

Esta funcion sirve para rellenar un MsFlexGrid, a traves de una SQL, ademas, ajusta el ancho de los campos al contenido de los mismos.

Saludos, Luis Navarro
[email protected]


El c�digo:

'
Public Sub ReGrid(strSQL As String, Grid As MSFlexGrid)
dim gDb as DataBase
Dim rRes As Recordset
Dim i As Integer
Dim iFila As Integer

    Set rRes = gDb.OpenRecordset(strSQL)
    Grid.Cols = rRes.Fields.Count
    Grid.Row = 0
    For i = 0 To rRes.Fields.Count - 1
        Grid.Col = i
        Grid = rRes.Fields(i).Name
    Next i
    
    Grid.Rows = 2
    iFila = 1
    Grid.Row = iFila
    Do While Not rRes.EOF
        For i = 0 To rRes.Fields.Count - 1
            Grid.Col = i
            If Not IsNull(rRes.Fields(i)) Then Grid = rRes.Fields(i)
            If Grid.ColWidth(i) < Len(rRes.Fields(i)) * 120 Then Grid.ColWidth(i) = Len(rRes.Fields(i)) * 120
        Next i
        iFila = iFila + 1
        Grid.Rows = iFila + 1
        Grid.Row = iFila
        rRes.MoveNext
    Loop
    Grid.Rows = iFila
End Sub

 


ir al índice