如何对过滤后的列表框进行排序

时间:2019-04-29 09:55:52

标签: vba ms-access access-vba access ms-access-2016

我已经为表单中的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只需删除引号即可。

1 个答案:

答案 0 :(得分:1)

删除引号逗号

& "ORDER BY [ID] ASC"