如何对筛选的ListBox进行排序

问题描述 投票:-1回答:1

我已经在表单中为ListBox创建了搜索框。搜索功能按预期工作,但我希望结果以第一列的升序显示。我无法理解如何做到这一点。我的代码:

Private Sub searchTB_Change()

Dim strSource As String, strSearch As String
'code for searching records
    strSearch = Replace(searchTB.Text, "'", "''")
    strSource = "SELECT [ID], [VP_veiklioji], [VP_invented_name], [Pareisk_pav], [Par_gavimo_data], [Finished] " _
        & "FROM TerPar_Oldsys " _
        & "WHERE [ID] LIKE '*" & strSearch & "*' " _
        & "Or [VP_veiklioji] LIKE '*" & strSearch & "*' " _
        & "Or [VP_invented_name] LIKE '*" & strSearch & "*' " _
        & "Or [Pareisk_pav] LIKE '*" & strSearch & "*' " _
        & "Or [Par_gavimo_data] LIKE '*" & strSearch & "*' " _
        & "Or [Finished] LIKE '*" & strSearch & "*' " _
       'up to this part everything works
        'line below do not work (it gets whole code in red in debugger) and I do not know how to fix it
        & "ORDER BY"  "[ID]" ASC," 

    'bottom two lines work too, I have tryed DoCmd.SetOrderBy but do not understand how to make it work either

    Me.oldListBox.ColumnWidths = "1.5 cm; 3 cm; 4 cm; 4 cm; 2 cm; 0.6 cm"
    Me.oldListBox.RowSource = strSource

End Sub

编辑:在我看来它不是重复,因为我的目标是完全不同的架构,结果只需要引用删除Gustav建议。

vba ms-access access-vba access ms-access-2016
1个回答
1
投票

删除引号和逗号:

& "ORDER BY [ID] ASC" 
© www.soinside.com 2019 - 2024. All rights reserved.