2011-10-12 73 views
2

我在訪問表單上有3列的列表框,它有行值源列表(不是來自數據庫的記錄集),它是以逗號分隔的字符串形式傳遞的。第三列是一個數值,我希望對第三列的列表框desc進行排序。基於值列表的訪問列表框 - 在列上排序

行來源是這樣的:

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

列表框正確填充。在這種情況下,我不知道如何在第三列對列表框進行排序。有任何想法嗎?

回答

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) 
+0

哇,這完美地工作。我能夠利用你的代碼來實現我的目標。謝謝 – Istari