I have created a list box which is populated from a table in a database.
I was wondering if there was a way to order the list by the primary number in the same table?
This is the code which lists the values:
varSQLCmd = "SELECT * FROM Dpt" varDptRecSet.Open varSQLCmd, varDptConn, adOpenStatic
DptCount = 0 If varDptRecSet.RecordCount > 0 Then varDptRecSet.MoveFirst Do While Not varDptRecSet.EOF lstDpt.AddItem varDptRecSet.Fields("Code") & " - " & varDptRecSet.Fields("Dpt") DptCount = DptCount + 1 varDptRecSet.MoveNext Loop End If
The field in the table which contains the primary ID is named "ID" this is the field i would like the list to be ordered by.
Thanks in advance
Martin
This conversation is currently closed to new comments.
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Visual Basic - Order By from Database
I have created a list box which is populated from a table in a database.
I was wondering if there was a way to order the list by the primary number in the same table?
This is the code which lists the values:
varSQLCmd = "SELECT * FROM Dpt"
varDptRecSet.Open varSQLCmd, varDptConn, adOpenStatic
DptCount = 0
If varDptRecSet.RecordCount > 0 Then
varDptRecSet.MoveFirst
Do While Not varDptRecSet.EOF
lstDpt.AddItem varDptRecSet.Fields("Code") & " - " & varDptRecSet.Fields("Dpt")
DptCount = DptCount + 1
varDptRecSet.MoveNext
Loop
End If
The field in the table which contains the primary ID is named "ID" this is the field i would like the list to be ordered by.
Thanks in advance
Martin