G
Guest
Hi,
I am writing code to generate dynamic SQL - depending on what the users
picks from combo boxes.
Everything nearly working 100% but Dates are driving me to despair!!
The dates I am using are as follows:
FromDate - 01/01/06 (1st Jan 2006)
ToDate - 31/12/10 (31st Dec 2010)
Access seems to do funny things - code wise it appears correct. when I take
the SQL statement generated and paste it in a new query window, Access seems
to jumbe up the 2nd Date to read #10/12/31#
The line of code that generated the SQL statement is:
varSQL = "SELECT Count(tblEvents.EventStatus) AS CountOfEventStatus FROM
tblEvents WHERE (((tblEvents.EventStatus)=" & Chr(34) & "held" & Chr(34) & ")
AND ((tblEvents.EventDate) Between " & Chr(35) & varFrom & Chr(35) & " and "
& Chr(35) & varTo & Chr(35) & "));"
which generates the following SQL statement:
SELECT Count(tblEvents.EventStatus) AS CountOfEventStatus FROM tblEvents
WHERE (((tblEvents.EventStatus)="held") AND ((tblEvents.EventDate) Between
#01/01/00# and #31/12/10#));
All looks good but the results are wrong. When I switch to Query Design
window the 2nd date appear jumbled and the between statements read:
Between #01/01/00# And #10/12/31#
Clearly an issue with the way Access SQL handles dates but for the life of
me I can't fix it!!
Help!!
I am writing code to generate dynamic SQL - depending on what the users
picks from combo boxes.
Everything nearly working 100% but Dates are driving me to despair!!
The dates I am using are as follows:
FromDate - 01/01/06 (1st Jan 2006)
ToDate - 31/12/10 (31st Dec 2010)
Access seems to do funny things - code wise it appears correct. when I take
the SQL statement generated and paste it in a new query window, Access seems
to jumbe up the 2nd Date to read #10/12/31#
The line of code that generated the SQL statement is:
varSQL = "SELECT Count(tblEvents.EventStatus) AS CountOfEventStatus FROM
tblEvents WHERE (((tblEvents.EventStatus)=" & Chr(34) & "held" & Chr(34) & ")
AND ((tblEvents.EventDate) Between " & Chr(35) & varFrom & Chr(35) & " and "
& Chr(35) & varTo & Chr(35) & "));"
which generates the following SQL statement:
SELECT Count(tblEvents.EventStatus) AS CountOfEventStatus FROM tblEvents
WHERE (((tblEvents.EventStatus)="held") AND ((tblEvents.EventDate) Between
#01/01/00# and #31/12/10#));
All looks good but the results are wrong. When I switch to Query Design
window the 2nd date appear jumbled and the between statements read:
Between #01/01/00# And #10/12/31#
Clearly an issue with the way Access SQL handles dates but for the life of
me I can't fix it!!
Help!!