|
-
Dec 2nd, 2002, 04:45 PM
#1
Thread Starter
Fanatic Member
*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
-
Dec 2nd, 2002, 04:51 PM
#2
Addicted Member
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?
-
Dec 2nd, 2002, 04:56 PM
#3
Thread Starter
Fanatic Member
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
-
Dec 2nd, 2002, 04:58 PM
#4
Addicted Member
That could be... however if you want to use VB variables then, your code should look like this:
VB Code:
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.
-
Dec 2nd, 2002, 05:18 PM
#5
Thread Starter
Fanatic Member
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
-
Dec 2nd, 2002, 05:21 PM
#6
Frenzied Member
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#)"
-
Dec 4th, 2002, 09:23 AM
#7
Thread Starter
Fanatic Member
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
-
Dec 4th, 2002, 09:35 AM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|