Vba 为什么我的WHERE子句在我的组合框中不起作用

Vba 为什么我的WHERE子句在我的组合框中不起作用,vba,ms-access,combobox,where-clause,Vba,Ms Access,Combobox,Where Clause,我有一个叫NameFilt的组合框。我希望行的来源如下: SELECT DISTINCT VoucherListTbl.BuyerName FROM VoucherListTbl WHERE (((VoucherListTbl.BuyerName) Is Not Null)) OR (((VoucherListTbl.BuyerName)<>"")); 然后显示不同的名称,列表顶部有一个空白选项,这是人们所期望的 请您解释一下为什么在输入VBA代码时WHERE子句对我不起作用 非常

我有一个叫NameFilt的组合框。我希望行的来源如下:

SELECT DISTINCT VoucherListTbl.BuyerName
FROM VoucherListTbl
WHERE (((VoucherListTbl.BuyerName) Is Not Null)) OR (((VoucherListTbl.BuyerName)<>""));
然后显示不同的名称,列表顶部有一个空白选项,这是人们所期望的

请您解释一下为什么在输入VBA代码时WHERE子句对我不起作用 非常感谢

如果您在中使用“”,它将断开字符串,这就是不工作的原因。使用
对引号进行编码,即原始字符串的结尾应类似于
”;“
或将
替换为
,然后重试

注意,相同的查询可以写成

SELECT DISTINCT BuyerName
FROM VoucherListTbl 
WHERE IsNull(BuyerName,'')<>''
选择不同的买方名称
来自VoucherListBL
其中为null(BuyerName),“”
Private Sub NameFilt_GotFocus()
Me.AllowEdits = True
Me.NameFilt.RowSource = "SELECT DISTINCT VoucherListTbl.BuyerName FROM VoucherListTbl;"
Me.NameFilt.Dropdown
End Sub
SELECT DISTINCT BuyerName
FROM VoucherListTbl 
WHERE IsNull(BuyerName,'')<>''