Public Sub SortDBGrid(dbg As DBGrid, dat As Data, Optional AscPmt As
Variant)
'//AscPmt: True:Ascendente (predeterminado), False: Descendente
Dim rs As Recordset
Dim Clause As String
Dim FieldName As String
Dim Asc As Boolean
Dim CurrCol As Integer
On Error GoTo SortErr
If IsMissing(AscPmt) Then
Asc = True
Else
Asc = CBool(AscPmt)
End If
CurrCol = dbg.Col
FieldName = dbg.Columns(CurrCol).DataField
If dat.Recordset.Fields(FieldName).Type = dbMemo Then
MsgBox "Los Campos Memo no son ordenables"
Exit Sub
End If
Screen.MousePointer = vbHourglass
Set rs = dat.Recordset
Clause = "[" + FieldName + "]"
If Not Asc Then
Clause = Clause + " DESC"
End If
rs.Sort = Clause
Set dat.Recordset = rs.OpenRecordset(rs.Type)
dbg.Col = CurrCol
dbg.SetFocus
Screen.MousePointer = vbDefault
Exit Sub
SortErr: '//Any procedure
End Sub