C
CBoyda
I think I have stumbled across yet another Access vs SQL syntax issue.
Using MS Access 2003 front end mdb with linked ODBC tables to SQL 2000
backend.
In the Access form I am just getting the functions working with access
queries and as time or resources are required I expect to convert them to SQL
stored procedures as necessary. Also eventually I expect this application
would/could be ported over to a web asp or .net app.
VBA Code:
strSQL = "SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID,
tbl_vacation.StartVacation, tbl_vacation.EndVacation FROM tbl_vacation " _
& " WHERE (((cvdate(tbl_vacation.StartVacation)) Between #" & CVDate(RS!
PaidUntil) & "# And #" & CVDate(Me.InvoiceDate) & "#)) Or (((cvdate
(tbl_vacation.EndVacation)) Between #" & CVDate(RS!PaidUntil) & "# And #" &
CVDate(Me.InvoiceDate) & "#)) Or (((#" & CVDate(RS!PaidUntil) & "#) Between
cvdate(tbl_Vacation.StartVacation) And cvdate(tbl_Vacation.EndVacation))) Or
(((#" & CVDate(Me.InvoiceDate) & "#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) " _
& " GROUP BY tbl_vacation.DaysVacationID, tbl_vacation.CustomerID,
tbl_vacation.StartVacation, tbl_vacation.EndVacation HAVING (((tbl_vacation.
CustomerID)=" & RS!CustomerID & "));"
Debug.Print "Customer Vacation SQL: " & Chr(10) & strSQL
Set rstCustomerVacation = CurrentDb.OpenRecordset(strSQL,
dbOpenSnapshot, dbReadOnly)
If rstCustomerVacation.EOF Then yadda yadda
The debug print statement outputs this:
SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.
StartVacation, tbl_vacation.EndVacation FROM tbl_vacation WHERE (((cvdate
(tbl_vacation.StartVacation)) Between #12/01/2006# And #31/12/2006#)) Or ((
(cvdate(tbl_vacation.EndVacation)) Between #12/01/2006# And #31/12/2006#)) Or
(((#12/01/2006#) Between cvdate(tbl_Vacation.StartVacation) And cvdate
(tbl_Vacation.EndVacation))) Or (((#31/12/2006#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) GROUP BY tbl_vacation.
DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.StartVacation,
tbl_vacation.EndVacation HAVING (((tbl_vacation.CustomerID)=1));
Now if I copy and paste this into an access query in design mode and then
look at the results I see this:
SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.
StartVacation, tbl_vacation.EndVacation FROM tbl_vacation WHERE (((cvdate
(tbl_vacation.StartVacation)) Between #12/01/2006# And #31/12/2006#)) Or ((
(cvdate(tbl_vacation.EndVacation)) Between #12/01/2006# And #31/12/2006#)) Or
(((#12/01/2006#) Between cvdate(tbl_Vacation.StartVacation) And cvdate
(tbl_Vacation.EndVacation))) Or (((#31/12/2006#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) GROUP BY tbl_vacation.
DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.StartVacation,
tbl_vacation.EndVacation HAVING (((tbl_vacation.CustomerID)=1));
NOTICE that my December first date has changed to a January 12th date???? (in
the first between statement)
So I looked into the fields a little closer because this seems to be in the
code at:
the spot > CVDate(RS!PaidUntil) <
So it seems that getdate() is the default SQL way of populating that field
and when Access views it things start reverting the dd/mm vs mm/dd - *insert
incompaibility scream here*
I have check out http://allenbrowne.com/ser-36.html but the reality seems to
be one of 2 solutions.
a) do not use getdate (SQL) and everytime I insert a date use the cvdate()
function but then won't this die a horrible death when I try to convert this
access query into a stored procedure?
b) use getdate and ________ (magically somehow) tell access to quite doing
stupid automatic date flipping if the query says #01/12/2006# that means
december 1st not Janaury 12th... grrr.
For side notes:
This really comes down to how do I prepopulate the PaidUntil (date/time)
field? Using Getdate seems to be the easiest but then Access misinterprets
the information or have I totally missed something obvious?
Using MS Access 2003 front end mdb with linked ODBC tables to SQL 2000
backend.
In the Access form I am just getting the functions working with access
queries and as time or resources are required I expect to convert them to SQL
stored procedures as necessary. Also eventually I expect this application
would/could be ported over to a web asp or .net app.
VBA Code:
strSQL = "SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID,
tbl_vacation.StartVacation, tbl_vacation.EndVacation FROM tbl_vacation " _
& " WHERE (((cvdate(tbl_vacation.StartVacation)) Between #" & CVDate(RS!
PaidUntil) & "# And #" & CVDate(Me.InvoiceDate) & "#)) Or (((cvdate
(tbl_vacation.EndVacation)) Between #" & CVDate(RS!PaidUntil) & "# And #" &
CVDate(Me.InvoiceDate) & "#)) Or (((#" & CVDate(RS!PaidUntil) & "#) Between
cvdate(tbl_Vacation.StartVacation) And cvdate(tbl_Vacation.EndVacation))) Or
(((#" & CVDate(Me.InvoiceDate) & "#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) " _
& " GROUP BY tbl_vacation.DaysVacationID, tbl_vacation.CustomerID,
tbl_vacation.StartVacation, tbl_vacation.EndVacation HAVING (((tbl_vacation.
CustomerID)=" & RS!CustomerID & "));"
Debug.Print "Customer Vacation SQL: " & Chr(10) & strSQL
Set rstCustomerVacation = CurrentDb.OpenRecordset(strSQL,
dbOpenSnapshot, dbReadOnly)
If rstCustomerVacation.EOF Then yadda yadda
The debug print statement outputs this:
SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.
StartVacation, tbl_vacation.EndVacation FROM tbl_vacation WHERE (((cvdate
(tbl_vacation.StartVacation)) Between #12/01/2006# And #31/12/2006#)) Or ((
(cvdate(tbl_vacation.EndVacation)) Between #12/01/2006# And #31/12/2006#)) Or
(((#12/01/2006#) Between cvdate(tbl_Vacation.StartVacation) And cvdate
(tbl_Vacation.EndVacation))) Or (((#31/12/2006#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) GROUP BY tbl_vacation.
DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.StartVacation,
tbl_vacation.EndVacation HAVING (((tbl_vacation.CustomerID)=1));
Now if I copy and paste this into an access query in design mode and then
look at the results I see this:
SELECT tbl_vacation.DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.
StartVacation, tbl_vacation.EndVacation FROM tbl_vacation WHERE (((cvdate
(tbl_vacation.StartVacation)) Between #12/01/2006# And #31/12/2006#)) Or ((
(cvdate(tbl_vacation.EndVacation)) Between #12/01/2006# And #31/12/2006#)) Or
(((#12/01/2006#) Between cvdate(tbl_Vacation.StartVacation) And cvdate
(tbl_Vacation.EndVacation))) Or (((#31/12/2006#) Between cvdate(tbl_Vacation.
StartVacation) And cvdate(tbl_Vacation.EndVacation))) GROUP BY tbl_vacation.
DaysVacationID, tbl_vacation.CustomerID, tbl_vacation.StartVacation,
tbl_vacation.EndVacation HAVING (((tbl_vacation.CustomerID)=1));
NOTICE that my December first date has changed to a January 12th date???? (in
the first between statement)
So I looked into the fields a little closer because this seems to be in the
code at:
the spot > CVDate(RS!PaidUntil) <
So it seems that getdate() is the default SQL way of populating that field
and when Access views it things start reverting the dd/mm vs mm/dd - *insert
incompaibility scream here*
I have check out http://allenbrowne.com/ser-36.html but the reality seems to
be one of 2 solutions.
a) do not use getdate (SQL) and everytime I insert a date use the cvdate()
function but then won't this die a horrible death when I try to convert this
access query into a stored procedure?
b) use getdate and ________ (magically somehow) tell access to quite doing
stupid automatic date flipping if the query says #01/12/2006# that means
december 1st not Janaury 12th... grrr.
For side notes:
This really comes down to how do I prepopulate the PaidUntil (date/time)
field? Using Getdate seems to be the easiest but then Access misinterprets
the information or have I totally missed something obvious?