If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > "between #1/1/2001# and #12/31/2001#" doesn't work

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-12, 14:06
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 1,072
"between #1/1/2001# and #12/31/2001#" doesn't work

We're finally moving from Access97 to Access2010, and something that used to work, now throws an:

Code:
"ODBC call failed. [Oracle][ODBC] Syntax error or access violation. (#0)"
We can't put a date range into a query, like:

Code:
between #1/1/2001# and #12/31/2001#
or really, any kind of date comparison (like "> #1/1/2001#") without generating that error. If I set up the dates as parameters and get prompted for them at runtime, everything runs as expected.

Did this functionality get de-supported in Access2010?

Thanks,
--=Chuck
Reply With Quote
  #2 (permalink)  
Old 02-03-12, 14:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
dude, you're using msaccess syntax on an oracle database -- you gots to use oracle syntax
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-03-12, 15:02
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
As Access is capable of performing some translation, you could try:
Code:
"between " & #1/1/2001# & " and " & #12/31/2001#
I don't know with Oracle, but it works with MS SQL Server (2005 and 2008 R2).
__________________
Have a nice day!
Reply With Quote
  #4 (permalink)  
Old 02-03-12, 15:24
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 1,072
But I'm just typing this into the Query Editor, into the Criteria section, rather than building a string in VBA. So, Access2010 auto-populates my between statement with "#" around the dates. Plus, this same syntax works in Access97.

Also, we're using ODBC to connect to Oracle, and the same DSN for both Access97 and Access2010, and so this syntax is already being translated on my behalf by the driver, but only in Access97.

--=cf
Reply With Quote
  #5 (permalink)  
Old 02-03-12, 15:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
just for fun, type in '2001-01-01' and '2001-12-31' using single quotes instead of octothorps and in yyyy-mm-dd format in case oracle has problems with american dates
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 02-03-12, 15:49
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 1,072
Code:
Between '2001-01-01' And '2001-12-31'
Between '01-JAN-2001' And '31-DEC-2001'
All result in "Data type mismatch in query expression" (which is not the same error as above).

But parameters, and any expression which uses MSAccess functions which cast strings as dates, will work. Like the following, which definitely is not Oracle syntax, but works:

Code:
between CDate("1/01/2001") And CDate("01/31/2001")
I'm ok with teaching people CDate(), but we're talking hundreds of non-IT users who have learned to use octothorps (cool word) in their date expressions. I'd rather get those working again ... but if I can't, I can't

--=Chuck
Reply With Quote
  #7 (permalink)  
Old 02-03-12, 15:51
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
I tested with Access 2003 and Access 2010 and it works in both cases. Maybe it's something due to the Oracle driver. Did you tested the solution proposed by r937?
__________________
Have a nice day!
Reply With Quote
  #8 (permalink)  
Old 02-03-12, 15:55
chuck_forbes chuck_forbes is offline
Registered User
 
Join Date: Dec 2003
Posts: 1,072
Same driver is in use for Access97 and Access2010, which uses the Oracle 11.1.0.7 client.
--=cf
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On