473,748 Members | 5,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jul 19 '06 #1
5 2562
Henning M wrote:
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??
Are you /certain/ that you're using the /same/ SQL in both cases?

It's not even that your dates could be interpreted differently between
Access and your application so you'd get different results (#1/5/2006#?
1st of May or Jan 5th?) - there's no month 31 (yet)!

In your application, [always] print out (or log) your SQL before
executing it.

Next question (from someone with many, many Data Sources on their PC) -
Are you certain that you're using the same /database/ in both cases.
I've lost /hours/ trying to match up dodgy data only to find I've been
looking in completely the wrong database!

HTH,
Phill W.
Jul 19 '06 #2

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\'',Dat eFormat=''\'yyy y-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...

clsConvertDateT oString

Function fDateToString(b yVal 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.ToStri ng("s").SubStri ng(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 fDateTimeToStri ng

....

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 fStartDateToStr ing (adtmDate as Date) as string
Function fEndDateToStrin g (adtmDate as Date) as string
....

jeff.
"Henning M" <he*****@fys.ku .dkwrote in message
news:24******** *************** ****@news.arrow net.dk...
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

Jul 19 '06 #3
Access wants #USAformat# . Does not vary with culture.

-t

Henning M ha scritto:
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
Jul 19 '06 #4
oops the line

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

is the proper format...dates enclosed with a quotation mark...
"jeff" <jhersey at allnorth dottt comwrote in message
news:es******** ******@TK2MSFTN GP04.phx.gbl...
>
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\'',Dat eFormat=''\'yyy y-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...

clsConvertDateT oString

Function fDateToString(b yVal 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.ToStri ng("s").SubStri ng(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 fDateTimeToStri ng

...

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 fStartDateToStr ing (adtmDate as Date) as string
Function fEndDateToStrin g (adtmDate as Date) as string
...

jeff.
"Henning M" <he*****@fys.ku .dkwrote in message
news:24******** *************** ****@news.arrow net.dk...
>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


Jul 19 '06 #5
Thanks all for the quick respons..

As Phill W suggested using the SAME Database when trying out my Sql
statements and when running the app helped, and the last thing was the
format change from "ddmmyyyy" to "mmddyyyy"

Thanks all

Henning M

PS- Thanks Jess for the information about Access Vs. MSsql # as I later, DO
want the app to run with MSSql

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:e9******** **@yarrow.open. ac.uk...
Henning M wrote:
>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??

Are you /certain/ that you're using the /same/ SQL in both cases?

It's not even that your dates could be interpreted differently between
Access and your application so you'd get different results (#1/5/2006#?
1st of May or Jan 5th?) - there's no month 31 (yet)!

In your application, [always] print out (or log) your SQL before executing
it.

Next question (from someone with many, many Data Sources on their PC) -
Are you certain that you're using the same /database/ in both cases.
I've lost /hours/ trying to match up dodgy data only to find I've been
looking in completely the wrong database!

HTH,
Phill W.

Jul 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
5682
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from...
3
4836
by: Radu | last post by:
Hi. I have lots of processing to do on the server - from the client (Access) I call a sproc which returns a recordset (the sproc is essentially a big "select"). With the obtained data , I need to generate a report. How do I set the Recordsource of the report to the result of the select sproc ? I have tried the following, but it does not work. Private Sub cmdReport_Click()
1
4178
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a couple of tables in my database using INNER JOINS and the WHERE clause to specify the required constraints. However, I also want to read two fields from a *single* record from a table called 'Locations' and then apply one of these field's values...
2
3038
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can be associated with multiple categories. I have an "Issue," "IssueCategory," and "Category" in the database (among other tables). The form has a subform in it which is tied to the "IssueCategory" table. The main form is tied to the "Issue"...
4
1336
by: bill salkin | last post by:
The code below creates a dataset containing a table called "Customers" from the Northwind database Later on in my code, after the database connection is closed, I need to access this dataset to get all records with "ContactTitle" = 'Owner' and "City" = 'London'. I have tried using the SELECT and Find methods of dataset techbnology but I can't make them work with multi- criteria queries.Help!
2
1476
by: cephelo | last post by:
I have no problems outputting the attribute value when the node is in context, for example, @id when an <status> node is in context. However, I am having trouble outputting it in a <xsl:value-of /> element: <xsl:value-of select="procresults/settings@priority /> where it looks like
1
1433
by: U S Contractors Offering Service A Non-profit | last post by:
Craig Somerford to New, Harvard, (bcc:Natural) More options 7:56 pm (0 minutes ago) " Working in Faith " " SNOWING over New York City Today November 7th 2006 "
1
1645
by: U S Contractors Offering Service A Non-profit | last post by:
" Mentor-ship applied for November 8th 2006 " Craig Somerford to Harvard, Apple, Google, (bcc:Natural), (bcc:Matthew), (bcc:National), (bcc:Letters) Hide options 9:41 am (0 minutes ago) From: Craig Somerford <uscos@2barter.net> Mailed-By: gmail.com To: Harvard <rsvp@cyber.law.harvard.edu> Cc: Apple Web Associates Post Master <postmaster@webserver.com>, Google Maps <Google-Maps-API@googlegroups.com> Bcc: Natural Video Church...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.