“ SELECT ... FROM ... WHERE”中的AND语句

时间:2019-05-28 08:38:35

标签: vba ms-access access-vba

我在Access窗体中有ListBox,并尝试使用TextBox条目对其进行过滤。我的列表框由6列组成,我需要按2个条件对其进行过滤:

  • 我需要找到前5个中包含输入文本的所有条目 列
  • 第6列中包含特定文本。

过滤器或多或少有效,我通过输入获得过滤结果,但问题是我的代码似乎忽略了AND语句并显示了所有结果,尽管第6列未包含特定文本。我在做什么错了?

我的代码:

Sub PaieskaTb_Change()

Dim strSource As String, strSearch As String
strSearch = Replace(PaieskaTb.Text, "'", "''") 'needed to avoid errors if entry contains apostrophes

    strSource = "SELECT [ID], [VP_veiklioji], [VP_invented_Name], [Pareisk_pav], [Par_gavimo_data], [Statusas] " _
        & "FROM qryNewSys_srch " _
        & "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 & "*' " _
        & "And [Statusas] = 'Ongoing' " _ 'this line ignored, tried different apostrophes but no result
        & "ORDER BY [ID] DESC"


Me.Paraisku_sarasas.RowSource = strSource

End Sub

1 个答案:

答案 0 :(得分:2)

添加一组括号:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
     menu.clear();
     getMenuInflater().inflate(R.menu.game_menu, menu);
     return true;
}