我有下面的VBA代码,它在执行时返回标准表达式'中的'数据类型不匹配。我似乎无法找出它为什么给我这个错误。MS Access - 数据类型不匹配
任何人都可以帮助我吗?
VBA:
Public Function GezaagdeOmzet(ByVal TotaalPrijs As Double, ByVal AantalArtiklesPerOrder As Double, ByVal TotaalArtiklesPerOrder As Double, ByVal AantalArtiklesVerwijderedUitZaaglijst As Double) As Double
Dim result As Double
On Error GoTo ErrHandler
If IsNumeric(TotaalPrijs) = False Then
MsgBox ("TotaalPrijs not a number")
MsgBox (TotaalPrijs)
End If
If IsNumeric(AantalArtiklesPerOrder) = False Then
MsgBox ("AantalArtiklesPerOrder not a number")
MsgBox (AantalArtiklesPerOrder)
End If
If IsNumeric(TotaalArtiklesPerOrder) = False Then
MsgBox ("TotaalArtiklesPerOrder not a number")
MsgBox (TotaalArtiklesPerOrder)
End If
If IsNumeric(AantalArtiklesVerwijderedUitZaaglijst) = False Then
MsgBox ("AantalArtiklesVerwijderedUitZaaglijst not a number")
MsgBox (AantalArtiklesVerwijderedUitZaaglijst)
End If
If Not TotaalPrijs = 0 Then
If AantalArtiklesPerOrder > 0 Then
result = TotaalPrijs/(AantalArtiklesPerOrder * TotaalArtiklesPerOrder) * AantalArtiklesVerwijderedUitZaaglijst
On Error GoTo ErrHandler
Else
MsgBox ("AantalArtiklesPerOrder is null, Cannot do calculation")
End If
Else
MsgBox ("TotaalPrijs is null, cannot do division")
End If
Exit Function
ErrHandler:
MsgBox ("TotaalPrijs: " & TotaalPrijs & " TotaalArtiklesPerOrder: " & TotaalArtiklesPerOrder & " AantalArtiklesPerOrder: " & AantalArtiklesPerOrder & " AantalArtiklesVerwijderedUitZaaglijst: " & AantalArtiklesVerwijderedUitZaaglijst)
End Function
SQL查询在MS Access
GezaagdeOmzet: Sum(GezaagdeOmzet([TotaalPrijs],[tbl_ArtikelsPerOrder]![Aantal],[Totaal],[tbl_ArtikelVerwijderdUitZaaglijst]![Aantal]))
反正是有赶上我用VBA得到错误?
Cstr或CDec或CDbl不处理此错误。
感谢Remou,但是在查询中运行时,我被这个函数返回的一些字段中的奇怪'#Error'卡住了? – 2010-01-12 14:21:01
如果您将空值传递给您的函数,那么您将得到一个错误,我认为您是错误的。 – Fionnuala 2010-01-12 14:25:31
那么如何解决这些空值?有没有办法避开? – 2010-01-12 14:30:26