473,473 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Query between dates issue (inclusive)

AccessQuestion
13 New Member
I am at my wits end. Why is this not simple? So I am trying to query records that fall between two dates, but the ending date is not showing up. So, if I want to see if there is data for today my stopping date has to be tomorrow. Here is my SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT Tasks.[Start Date], Tasks.[Parts Used]
  2. FROM Tasks
  3. WHERE (((Tasks.[Start Date]) Between Forms![Parts Used Report]![Start Date] And Forms![Parts Used Report]![End Date])) And ((Tasks.[Parts Used]) Is Not Null);
  4.  
I have tried to add a +1 to the end date, to no avail. I have Googled my butt off and haven't found anything to help. Anything you can help me with on this would be GREATLY appreciated. Thanks in advance.

*edit*
I have also tried doing a >= and <= and I keep getting an error with the <=. Thanks again.
Jun 12 '10 #1
4 11743
gnawoncents
214 New Member
You were very close. Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Tasks.[Start Date], Tasks.[Parts Used]
  3. FROM Tasks
  4. WHERE (((Tasks.[Start Date])>=[Forms]![Parts Used Report]![Start Date] And (Tasks.[Start Date])<[Forms]![Parts Used Report]![End Date]+1) AND ((Tasks.[Parts Used]) Is Not Null));
  5.  
Jun 12 '10 #2
OldBirdman
675 Contributor
If the start and end dates in the table contain a time component, then any time after midnight 0:00:00 will be greater than the date without a time entered in the textbox of the form, and therefore fail the BETWEEN ... AND ... test.
Unless the DATEADD() function is used to add 1 day, that logic will fail also.
Also, the WHERE clause needs to explicitly state that the text be treated as a date, so the final result should look like:
Expand|Select|Wrap|Line Numbers
  1. WHERE (Tasks.[Start Date] Between #4/1/2010# And #6/30/2010# and ....
This is usually done in VBA by building an SQL string, and then running the query
Jun 12 '10 #3
AccessQuestion
13 New Member
@gnawoncents
Thank you so much gnawoncents!! The old position of the +1 mistake. It's working perfectly. Thanks again.
Jun 13 '10 #4
gnawoncents
214 New Member
Glad to hear it's working for you!
Jun 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Thomi Baechler | last post by:
Hello Everybody I run the following query against to identical databases. Execution time on the first DB is 0 seconds, on the other 6 seconds! SELECT dbo.HRMABZ.EMPKEY ,...
6
by: Sam | last post by:
Hi, In SQL Server when I create a stored procedure, in the list of stored procedures the Create Date column used to be formatted as: 28/09/2004 14:35:24 But since yesterday, for some reason, when...
0
by: Jason Franks | last post by:
Hello I am an amateur but enjoy a good go at access! I have a small, probably easy, query but I cant work the bloomin thing out! I need to create a report or 5 to show how classrooms are...
2
by: David | last post by:
Hi, I have the following SQL string, but cannot get it working: strSQL = "SELECT * FROM where . = '" & !!.! & "' and . = #" & !!.! & "#"
2
by: herlihyboy | last post by:
I have searched and can't find any articles pertaining to this issue... I am filling a dataset using a SqlDataAdapter that was instantiated with a SqlCommand object. When the Fill method is...
2
by: elevenx | last post by:
i need to query dates eg. records from 12-jan-99 to 03-sep-00. and then put these records in a report. help :confused:
2
by: jalmar | last post by:
Hello....I'm back again with the same question. I still haven't been able to figure out why my query isn't working. I am linking a table to an Excel spreadsheet, that part is fine, it is even...
5
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi, I posted last week about a problem I've got and didn't get any responses, but I've managed to come up with a workaround and a possible cause (guessing). I was wondering if someone could...
5
by: LifeFlasher | last post by:
Hrm, I'm not at all sure my title is clear, but I spent 15 minutes trying to figure out what my real problem was. I'm new here, and brand new to VB and I'm only trying to access a database, search...
5
by: hbaf208 | last post by:
I have an option group (TimeFrameOption) with three options: All, Last 6 months, and Last 12 Months. When an option is selected, I want to query dates in a listbox (CallReport) to display all dates...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.