Sql “错误”;“条件表达式中的数据类型不匹配”;
这段代码有错误“条件表达式中的数据类型不匹配”,我认为这是因为我的查询QryStockRinci中的strDate和数据不匹配 公共函数ReturnAmountSaleRev(strDate作为日期,strProductID作为字符串,curAmount作为货币,curAmountSale作为货币)作为变量Sql “错误”;“条件表达式中的数据类型不匹配”;,sql,ms-access,vba,ms-access-2007,Sql,Ms Access,Vba,Ms Access 2007,这段代码有错误“条件表达式中的数据类型不匹配”,我认为这是因为我的查询QryStockRinci中的strDate和数据不匹配 公共函数ReturnAmountSaleRev(strDate作为日期,strProductID作为字符串,curAmount作为货币,curAmountSale作为货币)作为变量 Dim将当前PO设置为整数 Dim varAmountSalePriorToCurrentPO作为变体 '获取当前ProductID在给定PO之前(含该PO)的总金额。 curAmount
Dim将当前PO设置为整数
Dim varAmountSalePriorToCurrentPO作为变体
'获取当前ProductID在给定PO之前(含该PO)的总金额。
curAmountSaleUpToCurrentPO=DSum(“Stock”、“QryStockRinci”和“[Tanggal]”您需要将日期视为日期而不是字符串,还要尝试将域函数用Nz括起来,以避免将空值赋给整数或变量以外的任何其他数据类型
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
Public函数ReturnAmountSaleRev(strDate作为日期,strProductID作为字符串,curAmount作为货币,curAmountSale作为货币)作为变量
Dim curAmountSaleUpToCurrentPO与长
Dim varAmountSalePriorToCurrentPO作为变体
'获取当前ProductID在给定PO之前(含该PO)的总金额。'
curAmountSaleUpToCurrentPO=Nz(DSum(“股票”、“QryStockRinci”,“[Tanggal]您能告诉我们哪一行是错误的吗?curAmountSaleUpToCurrentPO=DSum(“股票”、“QryStockRinci”,“[Tanggal]谢谢Paul,但它返回指向同一语句的溢出错误。您的值必须大于整数可以处理的值,请尝试将它们声明为Long。另外,请始终参考引发错误的代码行。否则很难识别。Paul,我对该函数有一个小问题。它返回wro如果同一产品有相同日期的数据,则为ng值。可能我需要添加一个字段行号来区分数据。您能帮助我吗?当然,如果您提供一些示例数据,这可能会有所帮助。我已经通过为该表添加自动编号字段解决了该问题,并按照我想要的顺序将数据插入该表排序
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