基于值列表访问列表框 - 在列上排序

时间:2011-10-12 10:42:31

标签: ms-access vba

我在访问表单上有一个包含3列的列表框,它的行源是一个值列表(不是db中的记录集),它以逗号分隔的字符串形式传递。第三列是数值,我希望在第三列上对列表框desc进行排序。

rowsource如下所示:

0,Standard price,1650,
14,Bookings made during Oct 2011,3770,
15,Minimum Stay 4 Nights - Special Price,2460

列表框正确填充。在这种情况下,我根本不知道如何按第三列对列表框进行排序。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

使用断开连接的记录集的一个非常粗略的想法:

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)