Reputation: 159
I have a datagrid linked to an access database in VB6. how do i sort the data in ascending order when the user clicks the command button.
My Code:
Private Sub Form_Load()
connSearch.Open connstr
Adodc1.ConnectionString = Conn.connstr
Set StudentTable.DataSource = Adodc1
Adodc1.Visible = False
End Sub
Private Sub cmdSort_Click()
Dim LNsql As String
connSearch.Close
connSearch.Open connstr
LNsql = "select * from Table1 order By LastName" & " " & StudentTable.Columns(2).Caption & "Asc"
StudentTable.Refresh
End Sub
Upvotes: 1
Views: 306
Reputation: 9726
If your recordset's CursorLocation
property is set to adUseClient you don't need to close and re-open the recordset. Just use the Recordset.Sort method.
Private Sub cmdSort_Click()
Adodc1.Recordset.Sort = "LastName" 'data field name
End Sub
Upvotes: 1