MS Access和DLookUp,ComboBox值和#Error

时间:2015-10-25 14:16:46

标签: ms-access combobox ms-access-2010

我试图找到"部门"来自表格" tblLenderAddress",其中"贷方"等于ComboBox" cmbLender"中的选定值。

出于调试目的,这很好用:

=DLookUp("[Department]","[tblLenderAddress]","Lender = 'Barclays'")

然而,这些不是:

=DLookUp("[Department]","[tblLenderAddress]","Lender = " & [Forms]![frmDetails]![cmbLender])

=DLookUp("[Department]","[tblLenderAddress]","Lender = " & [Forms]![frmDetails]![cmbLender].[Value])

=DLookUp("[Department]","[tblLenderAddress]","Lender = " & [Forms]![frmDetails]![cmbLender.value])

=DLookUp("[Department]","[tblLenderAddress]","Lender = " & [Me]![cmbLender])

我确定这是一个简单的解决方法,但谷歌在我试过的每个查询变体的前两页都让我失望。

2 个答案:

答案 0 :(得分:2)

工作DLookup示例中的第三个参数包括 Barclays 之前和之后的引号。

"Lender = 'Barclays'"

因此,当您根据组合框的当前值动态创建参数时,请包含这些引号...

"Lender = '" & Me!cmbLender.Value & "'"

答案 1 :(得分:1)

为了澄清,修复是;

  1. 将其设为“文字”而不是“价值”;和
  2. 在它周围放置文字包装。 '和'。
  3.   

    = DLookUp(“[Department]”,“[tblLenderAddress]”,“Lender ='”&   [表格]![frmDetails]![cmbLender]。[正文]& “'”)