Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 7th, 2007, 05:38 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
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! :)

Reply With Quote
  #2 (permalink)  
Old November 8th, 2007, 10:31 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #3 (permalink)  
Old November 8th, 2007, 12:03 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
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.

Reply With Quote
  #4 (permalink)  
Old November 8th, 2007, 12:07 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #5 (permalink)  
Old November 8th, 2007, 12:13 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
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.

Reply With Quote
  #6 (permalink)  
Old November 8th, 2007, 12:32 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
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 Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.