通过VBA代码将DLookup作为ControlSource

时间:2011-11-30 15:00:44

标签: ms-access vba access-vba ms-access-2003

以下是我的控制源并且有效:

=IIf(Forms!GARF!GARFsubForm![finished_good_#]<>"",DLookUp("[CustomerSKU]","ItemCustomerSKU","ItemNumber = '" & Forms!GARF!GARFsubForm![finished_good_#] & "' AND Customer = '" & Forms!GARF!customer & "' AND Company = '" & Forms!GARF!company & "' AND MarketingSeason = '" & DLookUp("[Code]","IDtoCode","ID = " & Forms!GARF!season_id) & "' AND Season = " & Forms!GARF!GARFyear),"")

我想通过VBA代码将其分配给另一个控制源:

Forms![GARF]![GARFsubForm]![SKU].ControlSource = (the above code)

Forms![GARF]![GARFsubForm]![SKU]是数据表中的一栏。

更新: 在Remou的帮助下,我能够提出以下工作解决方案: 代码在Form_Load事件上:

Forms![GARF]![GARFsubForm]![SKU].ControlSource = 
    "=IIf(Forms!GARF!GARFsubForm![finished_good_#]<>''," 
    & "DLookUp(""[CustomerSKU]"",""ItemCustomerSKU"",""ItemNumber = '"" 
    & Forms!GARF!GARFsubForm![finished_good_#] & ""' AND Customer = '" _
    & Forms!GARF!customer & "' AND Company = '" _
    & Forms!GARF!company & "' AND Season = " & Forms!GARF!GARFyear _
    & " AND MarketingSeason = '" 
    & DLookup("[Code]", "IDtoCode", "ID = " & Forms!GARF!season_id) & "'"")" & ",'')"

0 个答案:

没有答案