This SQL statement should be dead simple

Salient

Registered User.
Local time
Tomorrow, 06:22
Joined
Aug 14, 2007
Messages
63
sSql = "select * from Books where JournalMonth='" & txtMonth & "'"
[/quot]

Ends up with

select * from Books where JournalMonth='Aug-97'

It's not returning any data even though there are records matching the selection criteria :confused:

Anyone know if spaces in a cell could cause this issue?
 
When you use SQL in a query grid, you can use natural dates, however when you copy that code and use it in an SQL statement as a string, then the dates must be formatted correctly for SQL. In other words SQL is an American language and the dates must be formatted in the American format of month, day, year. Also the dates should be enclosed in the number character, the hash, #.

I produced a short video demonstrating various problems with dates here:

Thanks for the answer Gizmo but it's actually a text rather thna date field :)
 
Okay sussed it, SQL doesn't like the "-" in the selection data. A bit of use of the string function and a Like clause and away we go :) Drat, damn, who designed this database!
 
Code:
sSql = "select * from Books where JournalMonth=#" & txtMonth & "#"

should give you:
Code:
select * from Books where JournalMonth=#Aug-97#
#Aug-97# is a date.

If this doesn't work try
Code:
sSql = "select * from Books where CDate(JournalMonth)=#" & txtMonth & "#"
 

Users who are viewing this thread

Back
Top Bottom