Results 1 to 8 of 8

Thread: *RESOLVED* SQL statement "Type Mismatch" error

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    *RESOLVED* SQL statement "Type Mismatch" error

    I'm building sql on the fly based on user input. Everything works except this one that selects between two dates. I get the error: "Data type mismatch in criteria expression" at the line: rs.Open sql

    This is the sql statement:

    SELECT * FROM WOINFO WHERE (ConstDate BETWEEN "#4/1/2002#" AND "#4/30/2002#")

    I tried doing this with a variable because the field ConstDate is a Date field in the DB:

    SELECT * FROM WOINFO WHERE (ConstDate BETWEEN "#CDate(strCONDATE)#" AND "#CDate(strCONDATE2)#")

    But I still get type mismatch.

    If anyone spots something wrong with this any help is appreciated.

    JO
    Last edited by joltremari; Dec 4th, 2002 at 09:23 AM.
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  2. #2
    Addicted Member
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    202
    I'm not sure I understand why you are enclosing your dates (whether in a variable or not) in double quotes " "? Also are the variables VB variables?

  3. #3

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    They are vb variables

    Are you not supposed to put dates in double quotes, I thought the syntax was "#DateHere#"

    If it is not then that must be my trouble

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  4. #4
    Addicted Member
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    202
    That could be... however if you want to use VB variables then, your code should look like this:

    VB Code:
    1. strSQL = "SELECT * FROM WOINFO WHERE (ConstDate BETWEEN #" & strCONDATE "# AND #" & strCONDATE2 & "#)"

    [added] Dates are not supposed to be inside double-quotes... just the pound signs.

    [added 2] that is for SQL. In VB, they go in quotes.
    Last edited by BestCoder; Dec 2nd, 2002 at 05:02 PM.

  5. #5

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    How would it be written if I do not use a variable, if I "hardcode" certain dates in?

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  6. #6
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Originally posted by joltremari
    How would it be written if I do not use a variable, if I "hardcode" certain dates in?

    JO
    Code:
    strSQL = "SELECT * FROM WOINFO WHERE (ConstDate BETWEEN #12/2/02# AND #12/31/02#)"

  7. #7

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Sorry, I never said "thank you" that got me working. The syntax in sql statements always gets me

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  8. #8
    Addicted Member
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    202
    No Problem! Glad we could help. I am sure that andreys would say the same.

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