Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 542383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:26:27+00:00 2026-05-13T10:26:27+00:00

I have the follow VBA code and it returns a ‘ data type mismatch

  • 0

I have the follow VBA code and it returns a ‘data type mismatch in criteria expression‘ while executing. I cannot seem to find out why it is giving me this error.

Can anybody help me?

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 in MS Access

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

Is there anyway to catch the error I’m getting with VBA?

Cstr or CDec or CDbl is not handling this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:26:28+00:00Added an answer on May 13, 2026 at 10:26 am

    The above function is a little strange, as haarrrgh says.

    It should look more like the code below. You do not need to check that each of the arguments (TotaalPrijs, ByVal AantalArtiklesPerOrder etc) is a number, because you pass them As Double. If you pass anything except a number, such as a letter or Null, you will get an error. If this is not what you want, consider passing the arguments As Variant, you can then check that they are numbers. However, as you are using this in a query, I suggest that you do not use message boxes, if the argument is null, make it zero, if that is what it is supposed to be.

    Note also GezaagdeOmzet = , rather than result =

    EDIT re Comments

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will need a public IP address or domain name… May 13, 2026 at 8:40 pm
  • Editorial Team
    Editorial Team added an answer I'd say they are production ready - I'm using them… May 13, 2026 at 8:40 pm
  • Editorial Team
    Editorial Team added an answer I just made a test case on JS Bin which… May 13, 2026 at 8:40 pm

Related Questions

There’s a really cool diff class hosted by Google here: http://code.google.com/p/google-diff-match-patch/ I’ve used it
What are the implications of running a Microsoft Access Database in both 2003 and
I'm interested to know how I could improve the performance of SQL Server when
For software used in a call centre guiding agents through a set script they
The scenario is as follows, I have a list of options to be filled

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.