English 中文(简体)
管理系统接入——数据类型
原标题:MS Access - Data Type Mismatch

我有以下简称表:数据类型在标准表述中不匹配......>执行时。 我看不出为什么给我这个错误。

谁能帮助我?

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 Query inMS Access

GezaagdeOmzet: Sum(GezaagdeOmzet([TotaalPrijs],[tbl_ArtikelsPerOrder]![Aantal],[Totaal],[tbl_ArtikelVerwijderdUitZaaglijst]![Aantal]))

是否有一条途径来弥补I m与VBA的错误?

Cstr或CDec或CDbl没有处理这一错误。

最佳回答

如上所述,上述职能有些奇怪。

它应当更像以下法典。 你不需要核实每个论点(TotaalPrijs、BatVal Aantal ArtiklesPerOrder等)是个例子,因为你把这些论点当作双重观点。 如果除数人外,如信件或备忘录,你将出现错误。 如果这不是你想要的话,则考虑通过作为变式的论据,那么你就可以核实这些论点是编号。 然而,由于你在问询中使用了这种说法,我建议你不要使用电箱,如果这一论点无效的话,就会使其为零。

Note also GezaagdeOmzet = ,而不是结果 =

EDIT 评注

Public Function GezaagdeOmzet(ByVal TotaalPrijs As Variant, _
    ByVal AantalArtiklesPerOrder As Variant, _
    ByVal TotaalArtiklesPerOrder As Variant, _
    ByVal AantalArtiklesVerwijderedUitZaaglijst As Variant) As Double

    On Error GoTo ErrHandler

    If (Nz(AantalArtiklesPerOrder,0) * Nz(TotaalArtiklesPerOrder,0)) * _
       Nz(AantalArtiklesVerwijderedUitZaaglijst,0) = 0 Then
       GezaagdeOmzet = 0
    Else
        GezaagdeOmzet = Nz(TotaalPrijs,0) / _
        (Nz(AantalArtiklesPerOrder,0) * Nz(TotaalArtiklesPerOrder,0)) * _
       Nz(AantalArtiklesVerwijderedUitZaaglijst,0)
    End If

Exit Function

ErrHandler:
     MsgBox ("TotaalPrijs: " & TotaalPrijs & " TotaalArtiklesPerOrder: " _
    & TotaalArtiklesPerOrder & " AantalArtiklesPerOrder: " & AantalArtiklesPerOrder _
    & " AantalArtiklesVerwijderedUitZaaglijst: " _
    & AantalArtiklesVerwijderedUitZaaglijst)
End Function
问题回答

@Remou提供了我所看的工作解决办法,但他没有真正充分解释为什么他以不同的方式执行。 原因如下:

  1. 您的原有职能参数均被定义为“双重”。 这可能既不是Null,也不是非数字,因此,原法典对IsNumeric()的所有测试都是浪费时间的,因为它们永远不会返回FLSE。

  2. “标准表述中的数据类型不匹配”是一个非常常见的错误信息,从查询中可以将新数字传递给用户界定的职能,而这些功能在其参数中不能接受新数字。 澄清你的参数是一种办法,但各种变量可能导致各种问题,并失去强有力的数据分类。 我建议保留双重数据类型,并将CDbl(Nz([TotaalPrijs],0)从原始查询中删除。

Why do run a function which returns a double, only to convert it to a string and sum it up (even it s only a single value)?
I don t get it.

What happens if you run the function directly, not in a query?
Does it throw an error as well?

最后但并非最不重要的是,现在的职能似乎有两点。

(1) 如果Totaal ArtiklesPerOrder或Aantal ArtiklesVerjderedUitZaaglijst为0,就会犯错误(被抓获,但无论如何......)。 既然如此,你就在这一行中分了零:

result = TotaalPrijs / (AantalArtiklesPerOrder * TotaalArtiklesPerOrder) * AantalArtiklesVerwijderedUitZaaglijst

页: 1 检查TetaalPrijs是否为0,但你重新检查这一错误的轮.:有可能将零与任何区别开来,但不可能将任何内容分开by 0>。

2) The function will always return 0, because you calculate your result (in the variable "result"), but you don t return it. You have to do this explicitly:

GezaagdeOmzet = result




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...