It's often useful to sort a DBGrid field in either descending or ascending order. You do this by using the HeadClick event and the DataField property of columns. You must change the query string (Qry) with one of your own (be sure it contains the code in bold):
Private Sub DBGrid1_HeadClick(ByVal ColIndex As Integer)
Dim Qry as string
Qry = "SELECT * FROM MyTable WHERE Key='" _
& txtKey & "' "
Qry = Qry & "ORDER BY " & _
& " " & DBGrid1.Tag
data1.RecordSource = Qry
'toggle ASC and DESC keywords
If DBGrid1.Tag = "ASC" Then DBGrid1.Tag _
= "DESC" Else DBGrid1.Tag = "ASC"