Dim llngCount1 As Long
Dim llngCount2 As Long
Dim rs As New ADODB.Recordset
On Error GoTo ErrHndFillGrid
rs.Open Sql, conlocal, adOpenKeyset, adLockReadOnly
If rs.RecordCount <> 0 Then
rs.MoveLast
rs.MoveFirst
pGrid.Cols = rs.Fields.Count + 1
For llngCount1 = 0 To rs.Fields.Count - 1
pGrid.Row = 0
pGrid.Col = llngCount1 + 1
pGrid.Text = rs.Fields(llngCount1).Name
Next llngCount1
pGrid.Rows = rs.RecordCount + 1
For llngCount1 = 0 To rs.RecordCount - 1
pGrid.Row = llngCount1 + 1
pGrid.Col = 0
pGrid.Text = llngCount1 + 1
For llngCount2 = 0 To rs.Fields.Count - 1
pGrid.Col = llngCount2 + 1
If rs(llngCount2).Type = adDate Then
pGrid.Text = Format(rs(llngCount2), "dd-mmm-yyyy")
Else
pGrid.Text = Trim(rs(llngCount2)) & ""
End If
Next llngCount2
rs.MoveNext
Next llngCount1
FillGrid = True
Else
FillGrid = False
End If
rs.Close
Set rs = Nothing
Exit Function
ErrHndFillGrid:
FillGrid = False
End Function