ms-access
  • vba
  • access-vba
  • ms-access-2003
  • 2011-11-30 1 views 0 likes 
    0

    아래 내 컨트롤 소스이며 작동합니다을 DLookup 컨트롤 원본과 같은 VBA 코드를 통해

    =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),"") 
    
    I는 같은 VBA 코드를 통해 다른 제어 소스에 할당하고 싶은

    :

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

    Forms![GARF]![GARFsubForm]![SKU] 데이터 시트의 열입니다.

    UPDATE : 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) & "'"")" & ",'')" 
    

    답변

    1

    몇 가지 문제가 있습니다. 당신의 문자열이 무엇 반환이됩니다 (선명도 라인으로 구분) : 당신이 볼 수 있듯이

    =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),"") 
    

    는,이 두 가지가 거래되지 않는 그들은해야 : 추가가

    DLookUp([CustomerSKU],ItemCustomerSKU, 
    

    여기 공간 :

    & " ' AND Customer = '" & Forms!GARF!customer 
    

    유사 season_idfinished_good_# 텍스트인가?

    두 개의 '예 ='O''Reilly '

    편집

    당신과 함께 텍스트'당신의 발생을 탈출 특히, ""대신에 '작은 따옴표를 사용하는 것이 가능하다 코드에서이 작업을 수행하므로 쉽게 작업 할 수 있어야합니다. 예를 들면 다음과 같습니다.

    A = DLookup("[Code]", "IDtoCode", "ID = " & Forms!GARF!season_id) 
    B = "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 = '" & A & "'"")" 
    
    
    s = "=IIf(Forms!GARF!GARFsubForm![finished_good_#]<>''," & c & ",'')" 
    
    Debug.Print s 
    
    +0

    두 번째 DLookUp에 대해 몇 가지 따옴표가 누락되었습니다. 문자열을 별도로 구성하는 방법을 보여주기 위해 추가 참고를 추가했습니다. – Fionnuala

    +0

    @ 브루노 내 노트를 업데이트했습니다. BTW 단일 문자 변수는 완성 된 코드에 적합하지 않지만 테스트에 유용합니다. – Fionnuala

    +0

    감사합니다. 이제 CustomerSKU 열의 모든 행에 첫 번째 레코드의 SKU 번호가 표시됩니다. 코드를 업데이트했습니다. – Bruno

     관련 문제

    • 관련 문제 없음^_^