Using MS Access/Sort listbox

Advertisement


Question
Hey Ahmed, I have one listbox on a form which gets the data from a table. The table only have two columns: EquipmentID and Equipment. Then on my form I have one listbox which displays only the "Equipment". I want two buttons on the form: Button to sort equipment Ascending and another button to sort equipment Descending. Can you please answer this? Thanks

Answer
Both the the command buttons viz. cmdAsc and cmdDesc should have the following code in their On Click event procedure

Private Sub cmdAsc_Click()

 Me.List6.RowSource = "SELECT Table1.EquipmentId,Table1.Equipment FROM Table1 ORDER BY Table1.Equipment"
 Me.List6.Requery
   
End Sub

Private Sub cmdDesc_Click()
Me.List6.RowSource="SELECT Table1.EquipmentId,Table1.Equipment FROM Table1 ORDER BY Table1.Equipment DESC"
Me.List6.Requery
   
End Sub

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ahmed Sayed Aziz

Expertise

database designing,event driven programming,capturing/updating data programmitically using ms access 2000 and ms access 2002

Experience

multiple yrs. as a vb programmer

Organizations
Metal Industry

Publications
Math Skill Test VB6 Game Source Code published at Planet-Source --------------------------------------------------------------- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=72322&lngWId=1 Holy Quran Source Code published at Planet-Source ------------------------------------------------- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=72343&txtForceRefresh=82020091635140766 Right to Left Treeview & Listview Source Code published at Planet-Source ------------------------------------------------------------------------ http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=72376&lngWId=1

Education/Credentials
B.Com, ACMA(Associate member of Cost & Management Accountants Of India)

Awards and Honors
Wizard certificate from experts-exchange.com ============================================= http://www.experts-exchange.com/M_1214708.html Level 5 certificate from Yahoo!Answers ======================================= http://answers.yahoo.com/my/my;_ylt=AkjObjoI7Cr1x01J9syQ5RZ17hR.;_ylv=3

©2016 About.com. All rights reserved.