Solved Listbox.Recordset - Column Orders (1 Viewer)

allanc

Registered User.
Local time
Today, 02:34
Joined
Nov 27, 2019
Messages
46
Hello Friends,

Hope everyone is doing well!

I have a listbox on a form that displays data from a ADO recordset. How do we change the order of the columns on the list box? They seem to be ordered alphabetically.

Here is the code

Code:
Dim rs1 As New ADODB.Recordset

Set rs1 = New ADODB.Recordset

rs1.Open "SELECT ID, employee, department FROM [employees] WHERE ID =  " & employeeID & ", CurrentProject.Connection, adUseClient, adLockOptimistic, adCmdText

If rs1.RecordCount > 0 Then
    Set Me.resultTable.Recordset = rs1
End If

rs1.Close

The columns on the listbox are ordered alphabetically. I am wondering how can I change the order of these columns on the listbox.

Thank you!
Allan
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:34
Joined
Mar 14, 2017
Messages
8,779
Maybe you could change your Select statement. Do you really mean the order of the columns?
 

allanc

Registered User.
Local time
Today, 02:34
Joined
Nov 27, 2019
Messages
46
Maybe you could change your Select statement. Do you really mean the order of the columns?

Yes, the order of columns displayed on the listbox.

I would love the order of the columns to be the order of the SELECT statement but columns are ordered alphabetically on the listbox.

Thanks for your help!
 

allanc

Registered User.
Local time
Today, 02:34
Joined
Nov 27, 2019
Messages
46
Thinking of setting the column values individually instead of using ListBox.Recordset
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:34
Joined
Mar 14, 2017
Messages
8,779
Change your code to simply set the recordsource property to the select statement. Forget about opening a recordset.
 

allanc

Registered User.
Local time
Today, 02:34
Joined
Nov 27, 2019
Messages
46
Change your code to simply set the recordsource property to the select statement. Forget about opening a recordset.
Thank you!!! it worked!!

I assumed you meant Listbox.RowSource. The order is now same as my SELECT statement.

Have a great day!
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:34
Joined
Mar 14, 2017
Messages
8,779
Yes my bad, rowsource. Glad it worked. You too.
 

Users who are viewing this thread

Top Bottom