Results 1 to 13 of 13

Thread: datatype mismatch in criterion expression error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    datatype mismatch in criterion expression error

    Hi guys,

    I keep getting a "Data type mismatch in criterion expression" error.
    I cant figure out whats wrong, ive googled but still cant seem to find the problem.
    Code:
    Private Sub cmdSave_Click()
    
        c.Execute ("Update Addresses set buyerbookdate='" & txtBuyerbookdate.Value & "',buyerbooktime='" & txtBuyerbooktime.Value & "',bbratios='" & txtBuyerRatioS.Text & "' where orderno='" & Combo1.Text & "';")
        MsgBox "Records Added Successfully!", vbInformation, "Save"
    
    Exit Sub
    ErrHand:
        MsgBox Err.Description, vbCritical, "Error"
    End Sub
    Any help would be greatly appreciated!
    Brian

  2. #2
    Lively Member
    Join Date
    Jun 2008
    Location
    Bayang Magiliw, Perlas Ng Silangan
    Posts
    100

    Re: datatype mismatch in criterion expression error

    i suspect buyerbookdate field is a date/datetime type and on your update query you're setting a string type, also the same case with buyerbooktime , what are the types of these fields (buyerbookdate and buyerbookdate) in your database.

    for date field use #02/01/2011# instead of '02/01/2011'

    e.g.

    "Update Addresses set buyerbookdate=#" & txtBuyerbookdate.Value & "#, ...

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: datatype mismatch in criterion expression error

    What is the field type for orderno? If it is not text remove the single qoutes around Combo1.Text. As for the date suggestion in #2 if you are using access db ignore that otherwise follow it.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    Re: datatype mismatch in criterion expression error

    thanks for your replies. the orderno field is a text field, i am using an access database so how do i proceed from here?

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: datatype mismatch in criterion expression error

    The I would have you post the exact SQL that is being generated here. Also the field names in the table and thier data types.

    Do you know how to get the actuall SQL that is being generated and run?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6
    Lively Member
    Join Date
    Jun 2008
    Location
    Bayang Magiliw, Perlas Ng Silangan
    Posts
    100

    Re: datatype mismatch in criterion expression error

    is the field bbratios of type string? if not remove " ' " single quote arround the txtBuyerRatioS.Text

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    Re: datatype mismatch in criterion expression error

    buyerbookdate and buyerbooktime(fields) are date/time fields in access.
    no, i dont know how to get the actual sql... ?

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: datatype mismatch in criterion expression error

    Set a breakpoint. step though the code line by line. Once you get to the line after you generate the SQL statement you can right click on the var. Once you do that you should get a menu to display the value. Also you can set watchs on variables that will let you know when on changes and what it contains after the change.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    Re: datatype mismatch in criterion expression error

    gosh, i have a lot to learn, ive never use breakpoints and watches and stuff before, i just run the program and wait for errors (really terrible i know)

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: datatype mismatch in criterion expression error

    You really need to learn to use breakpoints it is the minimum you need to be able to debug a program
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    Re: datatype mismatch in criterion expression error

    off to google i go! thanks.
    Any pointers on the initial problem ?

  12. #12
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: datatype mismatch in criterion expression error

    You havae issues in the SQL Statement. Either a field in named wrong/spelled worng or the datatype is not passing what you expect.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    105

    Re: datatype mismatch in criterion expression error

    thanks for you help , much appreciated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width