以下是我的控制源并且有效:
=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) & "'"")" & ",'')"