Dim spql As String
Dim ab, cd As Double
spql = "select * from emp"
RS.Source = spql
RS.Open
If RS.RecordCount > 0 Then
For i = 1 To RS.RecordCount
ab = RS.Fields("salary"

cd = RS.Fields("Netsalary"

RS.MoveNext
Next i
End If
RS.close
'here we will get the totals.
Dim strsql As String
strsql = "SELECT * FROM emp order by salary"
'here you can write sorting quarry. Your last record
' will not be effected
RS.Source = strsql
RS.Open
With RS
Do While Not .EOF
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 0) = RS.Fields(0)
MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 1) = RS.Fields("salary"

MSFlexGrid .TextMatrix(MSFlexGrid.Rows - 1, 2) = RS.Fields("netsalary"

MSFlexGrid .Rows = MSFlexGrid.Rows + 1
Loop
End With
'here we will display the total records. And at the end
'this will display the totals.
MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = ab
MSFlexGrid.TextMatrix(MSFlexGrid.Rows - 1, 1) = cd
RS.close
'Try this this will solve your problem. Best of luck,"
Srinivas_pvl@hotmail.com