Results 1 to 9 of 9

Thread: SQL Statement error or Data Type error? (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member Apek's Avatar
    Join Date
    Aug 2002
    Location
    Kg Melayu,2 33 °N,102 10 °E
    Posts
    283

    Resolved SQL Statement error or Data Type error? (RESOLVED)

    VB Code:
    1. SELECT MC_NO, PART_CODE,MONTH " & _
    2.         "FROM MC_DATA " & _
    3.         "WHERE MC_NO = '& txtM1.Text &' AND MONTH = '" & txtMonthHide.Text & "'

    above is my sql statement...but i get an error "Data Type Mismatch in criteria expression. i think the error refers to MC_NO = '& txtM1.Text &', because there is no value when i debugged it.FYI the data type for MC_NO in MS Access database is Number..can somene correct my coding mistake??
    Thanks in advance.
    Last edited by Apek; Apr 25th, 2005 at 12:58 AM. Reason: Resolved
    "The reason you see open source there at all is because we came in and said there should be a platform that's identical with millions and millions of machines."
    Get it HERE


    Regards..
    Apek

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: SQL Statement error or Data Type error?

    Apek,

    First, You should always do something like this to eliminate simple SQL mistakes:

    strSQL = "Select ...."
    Debug.Print strSQL

    This will allow you to see really simple mistakes.

    Dates in Access must be surrounded by # signs

    MONTH = #" & txtMonthHide.Text & "#"

  3. #3

    Thread Starter
    Hyperactive Member Apek's Avatar
    Join Date
    Aug 2002
    Location
    Kg Melayu,2 33 °N,102 10 °E
    Posts
    283

    Re: SQL Statement error or Data Type error?

    emm..actually theres nothing wrong with the MONTH field because although i set the data type to Text, the value in the field is 200504 (YYYMM format).
    i think the MC_NO = '& txtM1.Text &' is the problem because the data type in Access is Number, but i dont know what to use in SQL Statement for number in VB.Anyone know?

    how to use the debug.print?
    is it will print the error on the form or what?
    "The reason you see open source there at all is because we came in and said there should be a platform that's identical with millions and millions of machines."
    Get it HERE


    Regards..
    Apek

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Statement error or Data Type error?

    Try....
    VB Code:
    1. SELECT MC_NO, PART_CODE,MONTH " & _
    2.         "FROM MC_DATA " & _
    3.         "WHERE MC_NO = " & txtM1.Text & " AND MONTH = '" & txtMonthHide.Text & "'
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Hyperactive Member Apek's Avatar
    Join Date
    Aug 2002
    Location
    Kg Melayu,2 33 °N,102 10 °E
    Posts
    283

    Re: SQL Statement error or Data Type error?

    well done!!it works now...
    "The reason you see open source there at all is because we came in and said there should be a platform that's identical with millions and millions of machines."
    Get it HERE


    Regards..
    Apek

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: SQL Statement error or Data Type error?

    If you put
    VB Code:
    1. Debug.Pring strSQL
    you will get a look at how the sql string looks to the computer.
    It will get printed in the Immediate window of the IDE.
    You can open the Immediate Window by pressing control-g

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Statement error or Data Type error?

    A rule of thumb is dont enclose your criteria with single quotes when the data type is a number....

    Anyway, mark your thread as [resolved] and select the checkmark icon if your problem is already solved....
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: SQL Statement error or Data Type error?

    Apek,

    You are correct I misread. For the month you do not need the # sign. Is the month a text field in the database?

  9. #9

    Thread Starter
    Hyperactive Member Apek's Avatar
    Join Date
    Aug 2002
    Location
    Kg Melayu,2 33 °N,102 10 °E
    Posts
    283

    Re: SQL Statement error or Data Type error?

    yup.,its in Text type..its ok u misread it..
    happen to me all the time too...
    thanks guys for all the answer and explanations..
    really appreciate that..
    "The reason you see open source there at all is because we came in and said there should be a platform that's identical with millions and millions of machines."
    Get it HERE


    Regards..
    Apek

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