I have a Listbox with 3 columns on an access form which has as it's row source a value list (not a recordset from the db), which is passed as comma seperated string. The third column is a numeric val开发者_如何学Goue, and I wish to sort the listbox desc on that third column.
The rowsource looks like this:
0,Standard price,1650,
14,Bookings made during Oct 2011,3770,
15,Minimum Stay 4 Nights - Special Price,2460
The listbox populates correctly. I just have no idea how to sort the listbox by the third column in this case. Any ideas?
A very rough idea using disconnected recordset:
Dim rs As New ADODB.Recordset
slist = "0,Standard price,1650," _
& "14,Bookings made during Oct 2011,3770," _
& "15,Minimum Stay 4 Nights - Special Price,2460"
With rs
.ActiveConnection = Nothing
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
With .Fields
.Append "Field1", adInteger
.Append "Field2", adVarChar, 200
.Append "Field3", adInteger
End With
.Open
ary = Split(slist, ",")
For j = 0 To UBound(ary)
.AddNew
For i = 0 To 2
.Fields(i).Value = ary(j)
j = j + 1
Next
j = j - 1
Next
.Sort = "Field3"
End With
slist = rs.GetString(, , ",", ",")
slist = Left(slist, Len(slist) - 1)
精彩评论