此代码有错误"数据类型在条件表达式中不匹配",我认为是因为我的查询QryStockRinci中的strDate和数据。
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 :(得分:0)
您需要将日期视为日期而不是字符串,还尝试将域函数与Nz一起包含,以避免将Null值分配给Integer或Variant以外的任何其他数据类型。
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