Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query String as a Date

Status
Not open for further replies.

msl3v

Programmer
Joined
Jul 2, 2008
Messages
2
Location
US
In out group database, we have a string field [Recovery_Date] that I need to query - using Visual Basic - as a Date-type. I've tried with (variations of) this snippet

SELECT * FROM RB_LOCAL WHERE CDate([Recovery_Date]) = " & Date

Is it possible to query a string type as another data type?
 
It is.
What does
Code:
CDate([Recovery_Date])
look like in a query if used outside the where clause?

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 





Also you have to be careful of date expressions that are looking for ONE SPECIFIC date, as your data may not have that exact value.

Also you did not include ALL your code, so who knows???
Code:
s = "SELECT * FROM RB_LOCAL WHERE CDate([Recovery_Date]) = #" & Date & "#"


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hello, thanks for the replies:

Using

"SELECT CDate([Recovery_Date]) FROM RB_LOCAL"

returns, for example, #10/9/1991#.

So, following Skip's recommendation, I tried

"SELECT * FROM RB_LOCAL WHERE CDate([Recovery_Date]) > #" & Date & "#"

... which results in a "Data type mismatch in criteria expression" error.
(Note, '>' not '='. I mistyped the original message)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top