1

我有 2 个表,如下所示。我需要使用表 [tblTransmittalls] 的 [TRANSMITTAL] 值更新表 [ASBUILT_LIST] 的 [incomming lettercontractor] 字段

我使用了以下更新查询

UPDATE ASBUILT_LIST INNER JOIN tblTransmittalls 
   ON ASBUILT_LIST.DOC=tblTransmittalls.DocumentNo 
SET ASBUILT_LIST.[incomming letter   contractor] = [tblTransmittalls]![TRANSMITTAL]
    WHERE  ((tblTransmittalls.PurposeofIssue)="FIN"));

现在,当 [DocumentNo] 字段(在 2 个表之间相关)没有任何匹配项时,我需要将 [incomming lettercontractor] 更新为NULL值。

SET ASBUILT_LIST.[incomming letter contractor] = Null

当有匹配时,它会像以前一样更新:

SET ASBUILT_LIST.[incomming letter contractor] = [tblTransmittalls]![TRANSMITTAL]

这些表是:

表:ASBUILT_LIST

doc                 incomming letter contractor
------------------  ---------------------------
doc-1000            L-0001
doc-2000            L-0002

表:tblTransmittals

DocumentNo         TRANSMITTAL      PurposeofIssue
-----------------  ---------------  --------------
DOC-1000           T-0001           FIN
DOC-3000           T-0500           FIN
DOC-4000           T-0600           IFI
DOC-2000           T-0800           IFI

我需要一个更新的 ASBUILT_LIST 表,所以在运行更新查询后它应该是这样的:

doc            incomming letter contractor
-------------  ---------------------------
doc-1000       T-0001   
doc-2000       null
4

1 回答 1

1

如果我正确理解您的描述,这应该很容易使用DLookup().

UPDATE ASBUILT_LIST
SET [incomming letter contractor] = 
    DLookup
        (
            "TRANSMITTAL",
            "tblTransmittalls",
            "DocumentNo = '" & [DOC] & "' AND PurposeofIssue = 'FIN'"
        );
于 2013-10-16T07:03:26.530 回答