|
-
Dec 12th, 2006, 06:57 AM
#1
Thread Starter
Junior Member
[RESOLVED] Simple problem...I think
All i'm trying to do is retrieve records from the database which match a certain date, but for some reason i keep getting a 'type mismatch' error. I've writen it simply like this to show the syntax i have used.
VB Code:
temp = "6/12/2006"
GetData ("SELECT * FROM tblcosts WHERE start_date = '" & CDate(temp) & "'")
Could someone please to me what i'm doing wrong? I suspect its something stupidly simple. I've tried it with and without using 'cdate'
Cheers
-
Dec 12th, 2006, 07:01 AM
#2
Re: Simple problem...I think
Is it access...then use # around the date value or use DateValue function
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.
-
Dec 12th, 2006, 07:08 AM
#3
Thread Starter
Junior Member
Re: Simple problem...I think
 Originally Posted by ganeshmoorthy
Is it access...then use # around the date value or use DateValue function
I tried this and still get the same error.
VB Code:
temp = "6/12/2006"
GetData ("SELECT * FROM tblcosts WHERE start_date = '" & DateValue(temp) & "'")
The error is:
Unable to connect
data type mismatch in criteria expression
I know my code used to connect to the database is fine cos if i type
VB Code:
getdata("SELECT * FROM tblcosts")
it will display all the records.
-
Dec 12th, 2006, 07:19 AM
#4
Re: Simple problem...I think
it should be
VB Code:
"SELECT * FROM tblcosts WHERE start_date = DateValue ('" & Format(temp,"DD/MM/YYYY") & "')"
and what does this GetData...what is the data type of Start_date in your database...what database you are using...
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.
-
Dec 12th, 2006, 07:24 AM
#5
Thread Starter
Junior Member
Re: Simple problem...I think
Getdata is just a procedure which connects to an Access database via ADODB.
-
Dec 12th, 2006, 07:34 AM
#6
Re: Simple problem...I think
What is the field type into which you are trying to store this date?
-
Dec 12th, 2006, 12:28 PM
#7
Thread Starter
Junior Member
Re: Simple problem...I think
in access it is date/time
-
Dec 12th, 2006, 12:32 PM
#8
Re: Simple problem...I think
 Originally Posted by Rincewind
in access it is date/time
Then you will need to encapsulate you date variable with the # signs as ganeshmoorthy pointed out in Post #2. This is something that Access requires.
-
Dec 12th, 2006, 12:45 PM
#9
Thread Starter
Junior Member
Re: Simple problem...I think
Sorry for being dumb but i did try what i thought he meant and it says the line isn't writen properly. I've done it like this
VB Code:
GetData ("SELECT * FROM tblcosts WHERE start_date = '" & #temp# & "'")
Is that wrong yeah?
-
Dec 12th, 2006, 12:57 PM
#10
Re: Simple problem...I think
It is.. they are supposed to be used in place of ' , eg:
VB Code:
GetData ("SELECT * FROM tblcosts WHERE start_date = #" & temp & "#")
-
Dec 12th, 2006, 01:03 PM
#11
Thread Starter
Junior Member
Re: Simple problem...I think
Cool cheers guys...you're legends
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
|