問題描述
DLookup 表達式總是返回相同的記錄 (DLookup expression always returning the same record)
我有一個名為 ProductionReportLandscape
的表單,其中有一個名為 ProductMasterData
的表設置為其記錄源。
有一個名為 CartonDateFormat
的文本框控件(從 ProductMasterData
表中獲取其值)以及 上的未綁定文本框控件ProductionReportLandscape
。
數據庫中還有一個名為DateCodes
的表。DateCodes
表中的每條記錄都有一個名為 OutputDateCode
的字段。CartonDateFormat
是一個數值,可以是 1‑36 之間的任意數字。
我試圖讓未綁定的文本框控件從 OutputDateCode
對應於每條記錄的 CartonDateFormat
。
例如,如果 CartonDateFormat
為 13,那麼我希望文本框控件顯示 DateCodes 的記錄 13 中的
表。如果 OutputDateCode
CartonDateCode
是 14,那麼我希望文本框顯示來自記錄 14 的 OutputDateCode
等每個數字 1‑36。
我已經為未綁定的文本框構建了一個 DLookup
表達式控制源屬性,但它總是從第一條記錄返回 OutputDateCode
而不管什麼記錄被選中。
我無法弄清楚如何更改表達式以達到預期的結果。有什麼想法嗎?
=DLookUp("OutputDateCode","DateCodes","[CartonDateFormat] =" & [CartonDateFormat])
參考解法
方法 1:
You reference names CartonDateFormat
and CartonDateCode
. You indicate CartonDateFormat is a textbox but not what CartonDateCode is.
Unless DateCodes has field CartonDateFormat with carton codes, DLookup cannot find match.
The DLookup needs to use name of field in DateCodes table that has carton codes. If that is CartonDateCode, then change DLookup to:
=DLookUp("OutputDateCode","DateCodes","[CartonDateCode] =" & [CartonDateFormat])
(by Kyra Ledkins、June7)