VB Code:
Private Sub addData()
grdThis.ClearSelection
grdThis.Redraw = False
Dim rsLoadGrid As ADODB.Recordset
Dim strSql As String
Dim intCol As Integer
Dim intRow As Integer
Dim rsCol As Integer
Dim rowAlign As Integer
Dim lCol As Integer
On Error GoTo 0
strSql = "SELECT NameID, Name, Agency, ReportsTo, EmployeeOrTempIDNumber, EmailAddress, ACAPSID, LanID, TeamID, Extension, AUNumber, HireDate, "
strSql = strSql + " GraduationDate, Expectation, NumberOfFilesAssignedInTransition, NumberOfFilesOutOfTransition, DateDroppedOut, Products, HMDA, APR, CIP, LIA,"
strSql = strSql + " HINS , FINS, PricingEngine, Valuation, Fee, Title, VOI, Final FROM tblName ORDER BY HireDate, Name"
Set rsLoadGrid = New ADODB.Recordset
With rsLoadGrid
.CursorLocation = adUseClient
.Open strSql, cn, adOpenDynamic, adLockOptimistic
End With
With grdThis
intRow = 1
rsLoadGrid.MoveFirst
Do While Not rsLoadGrid.EOF
'Add the row (empty)
.AddRow
'.AddRow "" works for FlexGrid
'Set the values one cell at a time
For intCol = 1 To rsLoadGrid.Fields.Count
'recordset counter has to start from 0
rsCol = intCol - 1
'if you want to format the text for some columns differenly, use If/Else or Select Case here
'TextMatrix works for FlexGrid, need to use .CellText for SGrid2
.CellText(intRow, intCol) = (rsLoadGrid.Fields(rsCol).Value)
If IsNull(rsLoadGrid.Fields(rsCol).Value) Then
.CellText(intRow, intCol) = Empty
End If
'.TextMatrix(lngRow, lngCol) = p_objRecordset.Fields(lngCol).Value & ""
Next intCol
'Align date columns
rowAlign = intRow
.CellTextAlign(rowAlign, 12) = DT_RIGHT
.CellTextAlign(rowAlign, 13) = DT_RIGHT
.CellTextAlign(rowAlign, 17) = DT_RIGHT
'Increment our row counter
intRow = intRow + 1
'Move to the next row of data
rsLoadGrid.MoveNext
Loop
End With
'Autosize columns
Screen.MousePointer = vbHourglass
With grdThis
For lCol = 1 To .Columns
.AutoWidthColumn lCol
Next lCol
End With
Screen.MousePointer = vbDefault
grdThis.Redraw = True
rsLoadGrid.Close
Set rsLoadGrid = Nothing
End Sub