Results 1 to 10 of 10

Thread: [RESOLVED] Data type mismatch

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    169

    Resolved [RESOLVED] Data type mismatch

    hi all..
    I have a program that save Employee data into Access DB

    After i save a data and i want to update the data...the error message "Data type mismatch in criteria expression"..will be displayed.

    can someone tell me what should i do or change with my coding below.....

    badgeno---Numeric
    name,grade,project,area,remarks-----Text
    doj-------Datetime
    camp,monthly(checkboxes)-----text

    " update emp set badgeno='" & txtbadgeno.Text & "',name= '" & txtname.Text & "',grade= '" & txtgrade.Text & "', project='" & txtproject.Text & "',area='" & txtarea.Text & "',doj='" & txtdoj.Text & "',camp='" & Check1.Value & "',monthly='" & Check2.Value & "',remarks= '" & txtremarks.Text & "' where badgeno= '" & txtbadgeno.Text & "'"

  2. #2
    Addicted Member
    Join Date
    Jan 2007
    Posts
    143

    Re: Data type mismatch

    access database, right? well...

    for date/time data fields in access, you have to use

    VB Code:
    1. ,doj=#" & txtdoj.Text & "#,

    using single quotes for date/time data fields are good when using SQL Server


    Additional:::

    if the date is coming from a text field... another thing you should do is make sure the text follows the date format in the access database... if it's the Short Date, then do this first before inserting or updating the field in the database:

    VB Code:
    1. Format(txtdoj.Text, "mm/dd/yyyy")

    Additional Additional:::

    leinad is right... for numbers, do not use single quotes(').. it is not necessary, so badgeno can go as he said...
    Last edited by dev.rogee; Jan 10th, 2007 at 03:57 AM.

  3. #3
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Data type mismatch

    can u post the line where you get an error?

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Data type mismatch

    Don't nest numerics such as badgeno in single quotes.

    "set badgeno=" & txtbadgeno.Text & ",name..."
    "... where badgeno= " & txtbadgeno.Text

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    169

    Re: Data type mismatch

    Thanks for your replies.

    I removed single quotes for numeric fields.
    When I changed to doj=#" & txtdoj.Text & "# getting an errors "Syntax error in date in query expression ##"

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Data type mismatch

    Moved to Database forum

    What is the value of txtdoj.Text?

    And can you show us the fully built SQL string?
    (print it to the Immediate window, as shown in this FAQ thread)

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Data type mismatch

    Quote Originally Posted by si_the_geek
    What is the value of txtdoj.Text?
    It looks as if it's null - "Syntax error in date in query expression ##"
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Data type mismatch

    yes, I hope the txtdoj.Text is empty. You can do it in this way. Break the query statement like
    VB Code:
    1. Sql = "set badgeno=" & txtbadgeno.Text & ",name..."
    2. If Not Trim(txtdoj.Text) = "" Then
    3.     Sql = Sql & ", doj=#" & txtdoj.Text & "#"
    4. End If
    5. Sql = Sql & " Where where badgeno= " & txtbadgeno.Text
    Hope it helps
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Data type mismatch

    VB Code:
    1. Sql = "set badgeno=" & txtbadgeno.Text & ",name..."
    2. If IsDate(Trim(txtdoj.Text)) Then
    3.     Sql = Sql & ", doj=#" & txtdoj.Text & "#"
    4. End If
    5. Sql = Sql & " Where where badgeno= " & txtbadgeno.Text
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    169

    Re: Data type mismatch

    Thanks for your replies friends.
    I changed my code as follows and it works.Thanks.

    Private Sub cmdmodify_Click()

    searchcode = Trim(txtbadgeno.Text)
    sql = "select * from emp where badgeno= " & searchcode

    tmp_rs.Open sql, conn, adOpenDynamic, adLockOptimistic

    If tmp_rs.EOF = False Then
    tmp_rs("name") = txtname.Text
    tmp_rs("grade") = txtgrade.Text
    tmp_rs("project") = txtproject.Text
    tmp_rs("area") = txtarea.Text
    tmp_rs("doj") = txtdoj.Text
    ...
    ....
    ...

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