0

我正在尝试在消息框中显示供应商名称和选定的采购订单号(来自表单上的组合框)不需要 QA 的消息。从采购订单编号获取供应商编号的 DLookup 有效,但我似乎无法嵌套它以从单独的表中获取供应商名称字符串。我在这个嵌套的 DLookup 中缺少什么?

PO Number、Vendor Number 和 Vendor Name 都是字符串。

Private Sub VendorName_AfterUpdate()

    Debug.Print Me.VendorName.Value

    If DCount("*", "ZeroAudit", "PONumber='" & Me.PONumber & "' and VendorName='" & Me.VendorName & "'") = 0 Then
        MsgBox "Needs QA"
    Else
        MsgBox "Vendor " & DLookup("Vendor", "Vendors", "VendorNumber = " & (DLookUp("VendorNumber","POHeader","PONumber= [Forms]!QAChecker2!PONumber.Value"))) & " — Does NOT Need QA — DIM and RETAIL CHECK REQUIRED"
    End If
    Me.PONumber.SetFocus

End Sub
4

2 回答 2

0

你说:

PO Number、Vendor Number 和 Vendor Name都是字符串

因此,您需要DLookup用单引号将条件括起来,例如您在此处:

DCount("*", "ZeroAudit", "PONumber='" & Me.PONumber & "' and VendorName='" & Me.VendorName & "'")

您还需要在这里使用单引号:

DLookup("Vendor", "Vendors", "VendorNumber = '" & DLookUp("VendorNumber","POHeader","PONumber= [Forms]!QAChecker2!PONumber.Value") & "'")
                                             ^                                                                                        ^
                                             |                                                                                        |
                    Added single quotes -----+----------------------------------------------------------------------------------------+

但我也会回应@Mathieu Guindon 关于使用局部变量代替内联DLookup表达式的评论。

考虑一下下面的代码阅读起来有多容易 -

Private Sub VendorName_AfterUpdate()
    Dim strVen As String
    Dim strVNo As String

    If DCount("*", "ZeroAudit", "PONumber='" & Me.PONumber & "' and VendorName='" & Me.VendorName & "'") = 0 Then
        MsgBox "Needs QA"
    Else
        strVNo = DLookup("VendorNumber", "POHeader", "PONumber = [Forms]!QAChecker2!PONumber")
        strVen = DLookup("Vendor", "Vendors", "VendorNumber = '" & strVNo & "'")
        MsgBox "Vendor " & strVen & " — Does NOT Need QA — DIM and RETAIL CHECK REQUIRED"
    End If
    Me.PONumber.SetFocus
End Sub

DLookup您还可以用表达式包围Nz表达式以捕获空值,并在继续之前测试空字符串。

于 2019-08-29T21:22:01.947 回答
0

鲜为人知,但您也可以在过滤器中使用SQL :

DLookup("Vendor", "Vendors", "VendorNumber = (Select VendorNumber From POHeader Where PONumber = [Forms]!QAChecker2!PONumber.Value)")
于 2019-08-30T07:44:40.453 回答