Re: Access Databse "Select * from Bilag Where Mdates Between #1/1/2006# And #31/1/2006#"




try changing your format to yyyy/mm/dd for the dates and see if that works
....

I have this thing in the back of my head reminding that some time ago ... a
long time ago, 10 yrs or so ... that access interpretes dates differently in
the query builder than odbc / jet access ... When coding things in access
vba, I had to make such that in any dynamically created SQL statement the
date formats were always yyyy/mm/dd. I am not sure if this is correct now
or not, but for the past 10 yrs ... I have been formating dates to
yyyy/mm/dd when building dynamic SQL against any database - ORACLE, SQL
Server, Access, Sybase and so on ... and have not had any problems - does
not matter what the user's regional date settings are ... it always works
for me - and where available, I set the date time formats in the connect
string ... for mssql server ... <DateTimeFormat=''\'yyyy-mm-dd
hh:mm:ss\'',DateFormat=''\'yyyy-mm-dd\'", TimeFormat=''\'hh:mm:ss'">. I may
be wrong, but it works and is simple to implement ...

Food thought.... if you are generating the SQL Dynamically, I would create a
class that translates the 'date' portion of the where clause to a string for
you ... the reason for this is, if you ever decide to move your database to
MSSQL Sever, the '#' will fail all your date parameters...

create a class...

clsConvertDateToString

Function fDateToString(byVal adtmDate as Date) as String

Dim lsReturn as String
Dim lsEnclosure as String

Select Case <typeof Connection>
Case "ACCESS"
lsEnclosure = "#"
Case "MSSQL"
lsEnclosure = "#"
...
End Select

lsReturn = lsEnclosure + adtmDate.ToString("s").SubString(0,10) +
lsEnclosure

RETURN lsReturn

END

If you need to include the time portion of the date, either overload the
function or create another function....

Function fDateTimeToString

....

Also, since dates are stored as Date / Time fields in Access...if you have a
time portion of the date, you need to worry about missing records on the
last day using the between function...

2006 / 01 / 31 ... assume a 12:00am time ... if you have a record with 2006
/ 01 / 31 1:30am ... your query will not pick this up ... you will need to
append times to the end of your date ...
ie dtmDate Between #2006/01/01 00:00:00# and #2006/01/31 23:59:59#

to ensure you get all the records you are after ... again, only a concern if
you store the time along with the date in the table ...
you can do this by adding a few more functions...
Function fStartDateToString (adtmDate as Date) as string
Function fEndDateToString (adtmDate as Date) as string
....

jeff.


"Henning M" <henning@xxxxxxxxx> wrote in message
news:2403c$44be0055$3e3d8433$15022@xxxxxxxxxxxxxxxxxxx
Hi all,

I having some problems with Access and selecting records between dates..
When I try this in access, it works fine!!

"Select * from Bilag Where Mdates Between #1/1/2006# And #31/1/2006#"

But when I try it from my vb.net app, I get ALL the records in the tabel??
What goes wrong?
I haven't been able to find any info on the net, besides others having
problems of the same nature..
I have tried to change the date format to "MM/DD/YYY" but with same
result!!

Hope someone out there knows what is goint on

Thanks

Henning





.



Relevant Pages

  • Re: Query Help Please! Is a Weekly data format Possible?
    ... There are a number of string formats that work, ... "Tom Ellison" wrote: ... Is there a way to have this query group the data in a weekly format ...
    (microsoft.public.access.queries)
  • Re: FAQ Topic - How do I format a date with javascript? (2009-06-01)
    ... instead of a YYYY-MM-DD string also works; ... ISO 8601 Extended formats can be... ...
    (comp.lang.javascript)
  • Re: Another PL/I cant
    ... not a function that converts a string to its length expressed ... CVF apparently has real issues with this stuff. ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • RE: Fixed Length
    ... match these formats, but rather pull the existing, normal, formats from the ... and run a function to build that information into a string that you ... length and the total lenght of all the fields has to be 100 characters. ... JobId (8 char) ...
    (microsoft.public.access.modulesdaovba)
  • Re: Format Question
    ... MM/DD/YYYY 2:00 ... of the logical descending order of YYYY/MM/DD?) ... When you refill the two _copy variables, they'll be consumed on the next write. ... But the simplest way of all may be to avoid using formats. ...
    (perl.beginners)