Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2007, 05:38 PM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access Help: Using Between criteria with times

I have been having trouble with using "Between" in my criteria. Basically I have a [ARR] time and I am determining if the time fits between a [Start] time and a [5 Minute] time. Basically the [Start] and [5 Minute] times come from a table with every possibility between 0:00 and 23:59. My field is [ARR] and my criteria is: Between [TimeTable].[Start] And [TimeTable].[5 Minute]. So if the [ARR] time was 9:40 the following should be returned.

ARR Start 5 Minute
9:40 9:35 9:40
9:40 9:36 9:41
9:40 9:37 9:42
9:40 9:38 9:43
9:40 9:39 9:44
9:40 9:40 9:45

Basically each time should return 6 entries. However, what is returned is not consistent. For example, the return for the 9:40 [ARR] only shows 5 entries (it doesn't show 9:40-9:45 Start and 5 Minute). While another [ARR] time may not show the beginning time slot. I have tried to figure this out for a while now and don't have anything. PLEASE, anything would be appreciated! :)

 
Old November 8th, 2007, 10:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Are you using the correct delimiter with your query or VBA code? For Example:

"SELECT [AAR] FROM TimeTable WHERE [AAR] Between #" & [Start] & "# And #" & [5 Minute] & "#;"


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old November 8th, 2007, 12:03 PM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response! I tried typing in the following in my Criteria:

"SELECT [ARR] FROM TimeTable WHERE [ARR] Between #" & [Start] & "# And #" & [5 Minute] & "#;"

This returned the following prompt when I tried: Type mismatch in expression. I am not very familiar with this so I am not sure how to fix it.

 
Old November 8th, 2007, 12:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

What that error is saying is that some or all of the three fields (ARR, Start, and 5 Minute) are all not of the datatype of Date/Time. They should all be Date/Time for the statement to work. If any are strings, for example, you cannot compare date/times to string and the # delimiter will be incorrect.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old November 8th, 2007, 12:13 PM
Registered User
 
Join Date: Nov 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, I see. Well all the fields are in the Date/Time format when I check the original tables, so I can't see why that would be the issue.

 
Old November 8th, 2007, 12:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

OK, then the next question is are any of the them NULL or have no value? That is do you have any data left out? If Start or 5 Minute are null (have no data) then that will also cause the statement to fail. To compensate for that situation, try

"SELECT [AAR] FROM TimeTable WHERE [AAR] Between #" & Nz([Start], [Some Default Value for Start Here]) & "# And #" & Nz([5 Minute], [Some Default Value for 5 Minute Here]) & "#;"

The function Nz(X, Y) replaces a null/missing value with a default value. So if A = Nz(X, Y), then A = X if X is not missing, or A = Y if X is missing.

Note: if the five-minute value is always five mintues from start, don't store that in a field in a table. It bloats your dB size and violates dB rules. Just calculate it when you need it.

"SELECT [AAR] FROM TimeTable WHERE [AAR] Between #" & Nz([Start], [Some Default Value for Start Here]) & "# And #" & DateAdd("n", 5, Nz([Start], [Some Default Value for Start Here])) & "#;"

In that case [5 Minute] was replaced by the calculation DateAdd("n", 5, Nz([Start], [Some Default Value for Start Here]).

Check help for Nz() and DateAdd() for more details.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access VBA Report Criteria anterior Access VBA 17 October 24th, 2007 07:13 AM
ms access form as criteria on sql server backend ottos13 Access 1 September 13th, 2006 12:14 PM
Server times out chri74 Classic ASP Basics 4 September 17th, 2004 02:35 AM
script times out dazednconfused Beginning PHP 12 August 27th, 2003 07:32 AM
Local times pow1983 Forum and Wrox.com Feedback 4 June 9th, 2003 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.