PC Review


Reply
Thread Tools Rate Thread

Dates in a SQL Statement

 
 
NateBuckley
Guest
Posts: n/a
 
      30th May 2008
Hello,

I'm using ADODB to connect to an ACCESS database I've set up. I have a few
fields that are Date types and I send the SQL statement via a string, the
thing is I'm getting errors when trying to use Variables that are dates in
the string.

My SQL Statement

strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" & dateFrom & "'"

it'll turn my variable dateFrom into just a string. So doesn't match up when
it comes to putting this value into the database.

Anyway to make sure this gets put in as a Date type?

Sorry If that's unclear.

Nate
 
Reply With Quote
 
 
 
 
Andrew Taylor
Guest
Posts: n/a
 
      30th May 2008
I would use the following:
strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" &
Format(dateFrom,"yyyy-mm-dd") & "'"



On 30 May, 15:40, NateBuckley <NateBuck...@discussions.microsoft.com>
wrote:
> Hello,
>
> I'm using ADODB to connect to an ACCESS database I've set up. I have a few
> fields that are Date types and I send the SQL statement via a string, the
> thing is I'm getting errors when trying to use Variables that are dates in
> the string.
>
> My SQL Statement
>
> strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" & dateFrom & "'"
>
> it'll turn my variable dateFrom into just a string. So doesn't match up when
> it comes to putting this value into the database.
>
> Anyway to make sure this gets put in as a Date type?
>
> Sorry If that's unclear.
>
> Nate


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If/then statement between dates nybaseball22@gmail.com Microsoft Access Form Coding 1 11th Dec 2007 05:49 PM
IF Statement with Dates. cjwenngatz@gmail.com Microsoft Excel Programming 2 24th Oct 2007 06:14 PM
If statement with dates =?Utf-8?B?Vml2aWFuIEgu?= Microsoft Excel New Users 5 14th Sep 2006 08:27 AM
if statement with dates =?Utf-8?B?U2FuZm9yZCBMZWZrb3dpdHo=?= Microsoft Excel Misc 2 22nd Oct 2004 04:15 PM
dates and between statement =?Utf-8?B?Z2F4bWFuY0NP?= Microsoft Access Forms 1 9th Sep 2004 10:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:54 AM.