A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

= a date to include all the records (time problem)



 
 
Thread Tools Display Modes
  #1  
Old July 21st, 2007, 09:19 PM posted to microsoft.public.access.forms
Song Su
external usenet poster
 
Posts: 165
Default = a date to include all the records (time problem)

I have two combo boxes to allow user to select date range. My LogInTime
field has date and time. My following query would not select [cboTo] date,
only the day earlier. (If user, for example, select 7/20/07 in the cboTo, it
only displays records upto 7/19/07). If I add [cboTo]+1 and it says it's too
complecated.

SELECT Log.LoginTime
FROM Log
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


  #2  
Old July 21st, 2007, 10:06 PM posted to microsoft.public.access.forms
mike
external usenet poster
 
Posts: 3,942
Default = a date to include all the records (time problem)

Not sure but try this
WHERE (((Log.LoginTime) Between [Forms]![MainMenu]![cboFrom] And
[Forms]![MainMenu]![cboTo]))

"Song Su" wrote:

I have two combo boxes to allow user to select date range. My LogInTime
field has date and time. My following query would not select [cboTo] date,
only the day earlier. (If user, for example, select 7/20/07 in the cboTo, it
only displays records upto 7/19/07). If I add [cboTo]+1 and it says it's too
complecated.

SELECT Log.LoginTime
FROM Log
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));



  #3  
Old July 21st, 2007, 10:08 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default = a date to include all the records (time problem)

Try:
WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo];


Song Su wrote:
I have two combo boxes to allow user to select date range. My LogInTime
field has date and time. My following query would not select [cboTo] date,
only the day earlier. (If user, for example, select 7/20/07 in the cboTo, it
only displays records upto 7/19/07). If I add [cboTo]+1 and it says it's too
complecated.

SELECT Log.LoginTime
FROM Log
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #4  
Old July 23rd, 2007, 02:21 PM posted to microsoft.public.access.forms
Song Su
external usenet poster
 
Posts: 165
Default = a date to include all the records (time problem)

If my cboFrom and cboTo are not same day, it works fine. If they are same
day, no result shows in the query even though records exist.

"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:758558247fcc0@uwe...
Try:
WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo];


Song Su wrote:
I have two combo boxes to allow user to select date range. My LogInTime
field has date and time. My following query would not select [cboTo] date,
only the day earlier. (If user, for example, select 7/20/07 in the cboTo,
it
only displays records upto 7/19/07). If I add [cboTo]+1 and it says it's
too
complecated.

SELECT Log.LoginTime
FROM Log
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com



  #5  
Old July 23rd, 2007, 02:44 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default = a date to include all the records (time problem)

Between is supposed to be inclusive. If you change the cboFrom by one day
does it then also pick up the records from that single day you said had
records?

Song Su wrote:
If my cboFrom and cboTo are not same day, it works fine. If they are same
day, no result shows in the query even though records exist.

Try:
WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And

[quoted text clipped - 12 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200707/1

  #6  
Old July 23rd, 2007, 03:34 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default = a date to include all the records (time problem)

Between is inclusive, but since LogInTime contains both date and time, and
cboFrom and cboTo only include date, it's necessary to increment cboTo.

You need

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
DateAdd("d", 1, [Forms]![MainMenu].[cboTo]);

although

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1;

should have worked.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:759a9d6e9db58@uwe...
Between is supposed to be inclusive. If you change the cboFrom by one day
does it then also pick up the records from that single day you said had
records?

Song Su wrote:
If my cboFrom and cboTo are not same day, it works fine. If they are same
day, no result shows in the query even though records exist.

Try:
WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And

[quoted text clipped - 12 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));




  #7  
Old July 23rd, 2007, 07:29 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default = a date to include all the records (time problem)

Doug,
Wouldn't the DateValue() function strip out the time portion so you could
compare date to date?

Douglas J. Steele wrote:
Between is inclusive, but since LogInTime contains both date and time, and
cboFrom and cboTo only include date, it's necessary to increment cboTo.

You need

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
DateAdd("d", 1, [Forms]![MainMenu].[cboTo]);

although

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1;

should have worked.

Between is supposed to be inclusive. If you change the cboFrom by one day
does it then also pick up the records from that single day you said had

[quoted text clipped - 8 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com

  #8  
Old July 23rd, 2007, 07:57 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default = a date to include all the records (time problem)

Sorry, you're absolutely right. I missed the DateValue there.

However, applying DateValue to each row can be "expensive". It's far better
not to use the DateValue function, and add 1 to the End Date, since that
will only be executed once:

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And DateAdd("d", 1,
[Forms]![MainMenu].[cboTo])

or

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:759d18cd69523@uwe...
Doug,
Wouldn't the DateValue() function strip out the time portion so you could
compare date to date?

Douglas J. Steele wrote:
Between is inclusive, but since LogInTime contains both date and time, and
cboFrom and cboTo only include date, it's necessary to increment cboTo.

You need

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
DateAdd("d", 1, [Forms]![MainMenu].[cboTo]);

although

WHERE DateValue(Log.LoginTime) Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1;

should have worked.

Between is supposed to be inclusive. If you change the cboFrom by one
day
does it then also pick up the records from that single day you said had

[quoted text clipped - 8 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via http://www.accessmonster.com



  #9  
Old July 23rd, 2007, 08:16 PM posted to microsoft.public.access.forms
ruralguy via AccessMonster.com
external usenet poster
 
Posts: 1,172
Default = a date to include all the records (time problem)

Thanks Doug. Very good point but wouldn't you then pick up additional data
from the next day since Between is inclusive? Maybe switch to = and ??

Douglas J. Steele wrote:
Sorry, you're absolutely right. I missed the DateValue there.

However, applying DateValue to each row can be "expensive". It's far better
not to use the DateValue function, and add 1 to the End Date, since that
will only be executed once:

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And DateAdd("d", 1,
[Forms]![MainMenu].[cboTo])

or

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1

Doug,
Wouldn't the DateValue() function strip out the time portion so you could

[quoted text clipped - 21 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200707/1

  #10  
Old July 23rd, 2007, 08:24 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default = a date to include all the records (time problem)

Remember that the date data type is an 8 bytes floating point number, where
the integer portion represents the date as the number of days relative to 30
Dec, 1899, and the decimal portion represents the time as a fraction of a
day. In other words, 2:00 AM is stored as .083333, 4:00 AM is stored as
..166667, 6:00 AM is stored as .25 and so on. A date without a time is
midnight of that date (i.e.: the exact moment when the calendar changes from
the previous day to the given date). The odds of having an entry for
LoginTime with that precise time is extremely low, so it's usually
considered reasonable.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"ruralguy via AccessMonster.com" u12102@uwe wrote in message
news:759d825bc8744@uwe...
Thanks Doug. Very good point but wouldn't you then pick up additional
data
from the next day since Between is inclusive? Maybe switch to = and ??

Douglas J. Steele wrote:
Sorry, you're absolutely right. I missed the DateValue there.

However, applying DateValue to each row can be "expensive". It's far
better
not to use the DateValue function, and add 1 to the End Date, since that
will only be executed once:

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And DateAdd("d",
1,
[Forms]![MainMenu].[cboTo])

or

WHERE Log.LoginTime Between [Forms]![MainMenu].[cboFrom] And
[Forms]![MainMenu].[cboTo] + 1

Doug,
Wouldn't the DateValue() function strip out the time portion so you
could

[quoted text clipped - 21 lines]
WHERE (((Log.LoginTime)=[Forms]![MainMenu].[cboFrom] And
(Log.LoginTime)=[Forms]![MainMenu].[cboTo]));


--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200707/1



 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.