Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO SORT VB6 DATAGRID RECORDS 1

Status
Not open for further replies.

Hiccup

Programmer
Jan 15, 2003
266
US
This should be straight forward, but I can't get it to work.

My setup is VB6 and Access2K. On the VB Form I have an Adodc1, DataGrid1 and cmdButton1 and cmdButton2. I need the click code so that when cmdButton1 is clicked, it will sort all of the Records in the DataGrid by the "AptNo" field and when cmdButton2 is clicked, it will resort all of the Records by the "Tenant" field.

Any thoughts? Thanks in advance!
 
Private Sub cmdButton1_Click()
Adodc1.Recordset.Sort = "AptNo Asc"
End Sub

Private Sub cmdButton2_Click()
Adodc1.Recordset.Sort = "Tenant Asc"
End Sub

Swi
 
You can use Desc to sort the records in descending order if you wish.

Swi
 
Thanks Swi, I'll try it. Here's another star!
 
I had to fiddle with the syntax as I used an alias in my SQL - if you do here is an example

in SQL I had

tblMIUPatrolRoutes.fldPatrolBegins AS 'Patrol Begins'

and in the sort syntax I needed

Adodc1.Recordset.Sort = "['Patrol Begins']
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top