2014-07-24 106 views
0

此代碼有錯誤「標準表達式中的數據類型不匹配」,我認爲這是因爲strDate和我的查詢中的數據QryStockRinci。錯誤「標準表達式中的數據類型不匹配」

Public Function ReturnAmountSaleRev(strDate As Date, strProductID As String, curAmount As Currency, curAmountSale As Currency) As Variant

Dim curAmountSaleUpToCurrentPO As Integer Dim varAmountSalePriorToCurrentPO As Variant 'Get the total Amount for the current ProductID up to and including given PO. curAmountSaleUpToCurrentPO = DSum("Stock", "QryStockRinci", "[Tanggal] <= '" & strDate & "' AND [kode_barcode] = '" & strProductID & "'") 'If there is enough in SalesAmount to cover the whole cost, return the whole Amount. If curAmountSale - curAmountSaleUpToCurrentPO >= 0 Then ReturnAmountSaleRev = Format(curAmount, "0.00") Else 'Get the the total Amount in ProductID prior to current PO. varAmountSalePriorToCurrentPO = DSum("Stock", "QryStockRinci", "[Tanggal] < '" & strDate & "' AND [kode_barcode] = '" & strProductID & "'") 'If current PO is first in ProductID, varAmountSalePriorToCurrentPO will be null; 'determine covered amount. If IsNull(varAmountSalePriorToCurrentPO) = True Then If curAmount <= curAmountSale Then ReturnAmountSaleRev = Format(curAmount, "0.00") Else ReturnAmountSaleRev = Format(curAmountSale, "0.00") End If Else 'If current PO is not first in ProductID, varAmountSalePriorToCurrentPO 'will have a value; determine the covered amount. varAmountSalePriorToCurrentPO = curAmountSale - varAmountSalePriorToCurrentPO If varAmountSalePriorToCurrentPO <= 0 Then ReturnAmountSaleRev = 0 Else ReturnAmountSaleRev = Format(varAmountSalePriorToCurrentPO, "0.00") End If End If End If

端功能

+0

你能告訴我們哪一行是錯誤嗎? – PaulFrancis

+0

curAmountSaleUpToCurrentPO = DSum(「Stock」,「QryStockRinci」,「[Tanggal] <='」&strDate&「'AND [kode_barcode] ='」&strProductID&「'」) –

回答

0

你需要把日期設置爲日期,而不是字符串,也儘量附上域函數與的Nz避免整數或任何其它數據類型比變等分配Null值。

Public Function ReturnAmountSaleRev(strDate As Date, strProductID As String, curAmount As Currency, curAmountSale As Currency) As Variant 
    Dim curAmountSaleUpToCurrentPO As Long 
    Dim varAmountSalePriorToCurrentPO As Variant 

    'Get the total Amount for the current ProductID up to and including given PO.' 
    curAmountSaleUpToCurrentPO = Nz(DSum("Stock", "QryStockRinci", "[Tanggal] <= " & Format(strDate, "\#mm\/dd\/yyyy\#") & " AND [kode_barcode] = '" & strProductID & "'"), 0) 

    'If there is enough in SalesAmount to cover the whole cost, return the whole Amount.' 
    If curAmountSale - curAmountSaleUpToCurrentPO >= 0 Then 
     ReturnAmountSaleRev = Format(curAmount, "0.00") 
    Else 
     'Get the the total Amount in ProductID prior to current PO.' 
     varAmountSalePriorToCurrentPO = Nz(DSum("Stock", "QryStockRinci", "[Tanggal] < " & Format(strDate, "\#mm\/dd\/yyyy\#") & "' AND [kode_barcode] = '" & strProductID & "'"), 0) 

     'If current PO is first in ProductID, varAmountSalePriorToCurrentPO will be null;' 
     'determine covered amount.' 
     If IsNull(varAmountSalePriorToCurrentPO) = True Then 
      If curAmount <= curAmountSale Then 
       ReturnAmountSaleRev = Format(curAmount, "0.00") 
      Else 
       ReturnAmountSaleRev = Format(curAmountSale, "0.00") 
      End If 
     Else 
      'If current PO is not first in ProductID, varAmountSalePriorToCurrentPO 
      'will have a value; determine the covered amount.' 
      varAmountSalePriorToCurrentPO = curAmountSale - varAmountSalePriorToCurrentPO 

      If varAmountSalePriorToCurrentPO <= 0 Then 
       ReturnAmountSaleRev = 0 
      Else 
       ReturnAmountSaleRev = Format(varAmountSalePriorToCurrentPO, "0.00") 
      End If 
     End If 
    End If 
End Function 
+0

感謝Paul,但它返回溢出錯誤指向以相同的語句 –

+0

您的值必須是一個大於Integer可以處理的數字,嘗試將它們聲明爲Long。另外請始終參考拋出錯誤的代碼行。否則很難確定。 – PaulFrancis

+0

完成。謝謝保羅 –

相關問題