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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a datalist

Status
Not open for further replies.

pe

Technical User
Aug 8, 2001
31
US
I have a form (frmAdd) with a datalist (dlJobNo) on it that is bound to an access database using ADO. There is a cmdAddJobNo button on this form. This button opens frmAddJobNo that has a textbox txtAddJobNo. The user types into this box and then clicks the cmdAddJobNo button...

Private Sub cmdAddJobNo_Click()

On Error GoTo ErrLabel

Dim varx As Variant

'Set Provider
Set conn = New ADODB.Connection
conn.Provider = "Microsoft.JET.OLEDB.3.51"

'Open ps97.mdb as the Admin User
conn.Open "C:\_mfi\TP\ProjectServices\ps97.mdb", "admin", ""

'Load the recordset with data in Categories Table
Set rst = New ADODB.Recordset
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Source = "tblJobNo"
rst.ActiveConnection = conn
rst.Open
rst.AddNew
rst.Fields("JobNo") = txtAddJobNo.Text
rst.Update
rst.Requery

MsgBox ("Job Number added")
txtAddJobNo.Text = ""

rst.Close
conn.Close
frmAddJobNo.Hide
frmAdd.Show

Exit Sub

ErrLabel:
MsgBox Err.Description, vbInformation

End Sub


This works fine and updates the tblJobNo in ps97.mdb. I'd like, however, to sort the datalist (dlJobNo) on the frmAdd after the user adds more job numbers. How do I make the tblJobNo appear in alphabetical order when it populates the dlJobNo datalist?

Thank you for the help.
 
There's to ways u can sort the information one is with ur recorset.sort, THE default value is AscendiNG and u get it descending with DESC or something like, I don't have Basic in this computer but I am sure it is something like that.
Take a look to help for more information.
The SENCOND option is:
1. your opening the hole table WHY don't use an SQL sentece somthing like "SELECT * FROM tlbJobNo OrderBy JobNo"


Note: ----
Advise: If your sure that the table ur opening is gonna have less than 100 records what ur doing it's Ok. But if is not would be better Idea Insert using a command and doing ur select ForwardOnly and Lock : ReadOnly keeping the query in the order that u want.

fdalorzo@costarricense.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top