473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Query table by the date

Hi All,

I have a table tblProducts where I have four fields:\
Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate
(Date/Time - Medium Date)

The EnterDate is automatically filled (with Now()) and the purchase date is
entered manually.
Meantime I became aware that instead of Now() I should use Date() for the
date
The table had already records in it before I start working on it. Now I try
to query the table for all the records
where EnterDate = #25/06/2004#

The problem I have is that the query works fine only for the records where
the EnterDate contains only the date and not the time stamp. If I go in the
table and I click on EnterDate field for different records, I can see that
some of them are listed as 24-Jun-04 and stay like that when I click on
them, while others are listed as 25-June-2004 and change to 25/06/2004
11:34:44 AM when I click on them. How should I create a query which is able
to pick both types of EnterDate? At present my query works only for the
dates which weren't generated with Now()

Regards,
Nicolae


Nov 13 '05 #1
7 2417
Use an Update query to drop the time component from your existing fields.

1. Create a query into this table.

2. Change it to an Update: Update on Query menu.
Access adds an Update row to the grid.

3. Drag EnterDate field into the grid.

4. In the Update row beneath this field, enter:
DateValue([EnterDate])

5. In the Criteria row beneath this field, enter:
Is Not Null

6. Run the query.

This replaces the date/time value in all records with just the date value.

Presumably you have already changed the Default Value property of the field
to:
=Date()
to take care of future records as well.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I have a table tblProducts where I have four fields:\
Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate
(Date/Time - Medium Date)

The EnterDate is automatically filled (with Now()) and the purchase date is entered manually.
Meantime I became aware that instead of Now() I should use Date() for the
date
The table had already records in it before I start working on it. Now I try to query the table for all the records
where EnterDate = #25/06/2004#

The problem I have is that the query works fine only for the records where
the EnterDate contains only the date and not the time stamp. If I go in the table and I click on EnterDate field for different records, I can see that
some of them are listed as 24-Jun-04 and stay like that when I click on
them, while others are listed as 25-June-2004 and change to 25/06/2004
11:34:44 AM when I click on them. How should I create a query which is able to pick both types of EnterDate? At present my query works only for the
dates which weren't generated with Now()

Regards,
Nicolae

Nov 13 '05 #2
Hi Allen,

Thank you very much. I will do that, it is better to have the right kind of
data in the table. The problem is I am working with a small set of data, and
the real back end database is at the customer location. I will have to run
the query there.
Meantime I found a solution to be able to query the database, no matter of
the type of date I have in the table.
I used this kind of formatting:

SELECT ...
WHERE
(Format([DateEntered],"dd\/mm\/yyyy")=Forms!frmCustomersByDate!txtDate));

This gives me all the records, no matter if the date includes the time or
not.

Regards,
Nicolae
Nov 13 '05 #3
Okay. Can see what you are doing.

Because Access was designed in the US where they format their dates as
mm/dd/yyyy, there is a chance that your WHERE clause will be incorrectly
interpreted.

To make sure that doesn't happen:
1. If txtDate is an unbound text box, set its Format property to Short Date
so that Access knows it is a date (and also won't accept invalid entries.

2. Use DateValue() so you are dealing with a true date rather than a string
representation of the date (which Format() gives).

3. Declare the parameter in your query. In query design view, choose
Parameters from the Query menu, and in the dialog box, enter:
[Forms]![frmCustomersByDate]![txtDate] Date/Time

That comes from 11 years experience with Access in a dd/mm/yyy country. For
an explanation on avoiding these problems in general, see:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40******@duster.adelaide.on.net...

Thank you very much. I will do that, it is better to have the right kind of data in the table. The problem is I am working with a small set of data, and the real back end database is at the customer location. I will have to run the query there.
Meantime I found a solution to be able to query the database, no matter of
the type of date I have in the table.
I used this kind of formatting:

SELECT ...
WHERE
(Format([DateEntered],"dd\/mm\/yyyy")=Forms!frmCustomersByDate!txtDate));

This gives me all the records, no matter if the date includes the time or
not.

Regards,
Nicolae

Nov 13 '05 #4
Thank you very much, Allen. That information is very valuable.
I am not sure what parameters are. A few weeks ago I start building queries
by hand (in sql mode) and I defined parameters in the first line. And I
added those parameters in the where condition. But when I learnt to create
queries in the design mode, I noticed the parameters in the first line
weren't present anymore. What is the point of defining parameters, when I
can write straight in the Where conditon, like:
Where (tbTable.Field1 = Forms!MyForm!txtBox)
?

And I am not sure, but it seems that because of the first line, where I
defined parameters, I couldn't export the query to a mailmerge. Once we
removed the parameters line, we could create the mailmerge documents... (I
am not 100% sure, have to test more)
Regards,
Nicolae
Nov 13 '05 #5
A "parameter" is a value you supply at runtime for the query.
It causes Access to pop up a dialog asking for a value.

Any name that Access can't resolve to be a table or field name or a valid
word for SQL, it assumes to be a parameter. For example, you get the
parameter box if you misspell a field name.

While it is not essential to declare your parameters, it does help Access to
understand the data type and provide basic type-checking. For example, if
you declare a Date/Time parameter, and the user enters:
29/2/2005
Access will reprompt the user (because 2005 is not a leap year). If you do
not declare the parameter, and the user enters:
12/2/2005
will that be interpreted as Dec 2 or 12 Feb?
What about:
13/2/2005
Are you surprised at the difference between the last 2 examples?

How about:
29/2
Is that interpreted differently in a leap year than a normal year?
Or is there a chance that might Access interpret that entry as 29 divided by
2 = 14.5, which internally represents the date/time of noon on 13 Jan 1900?

There is too much scope for misunderstanding if you leave your parameters
undeclared and untyped.

The issue also arises for calculated fields in your queries. See:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Thank you very much, Allen. That information is very valuable.
I am not sure what parameters are. A few weeks ago I start building queries by hand (in sql mode) and I defined parameters in the first line. And I
added those parameters in the where condition. But when I learnt to create
queries in the design mode, I noticed the parameters in the first line
weren't present anymore. What is the point of defining parameters, when I
can write straight in the Where conditon, like:
Where (tbTable.Field1 = Forms!MyForm!txtBox)
?

And I am not sure, but it seems that because of the first line, where I
defined parameters, I couldn't export the query to a mailmerge. Once we
removed the parameters line, we could create the mailmerge documents... (I
am not 100% sure, have to test more)
Regards,
Nicolae

Nov 13 '05 #6
Allen, Great info. Made me open my eye's! I normally declare my parameters,
but more out of habit. I see the light now!

--
Reggie

----------
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40***********************@per-qv1-newsreader-01.iinet.net.au...
A "parameter" is a value you supply at runtime for the query.
It causes Access to pop up a dialog asking for a value.

Any name that Access can't resolve to be a table or field name or a valid
word for SQL, it assumes to be a parameter. For example, you get the
parameter box if you misspell a field name.

While it is not essential to declare your parameters, it does help Access to understand the data type and provide basic type-checking. For example, if
you declare a Date/Time parameter, and the user enters:
29/2/2005
Access will reprompt the user (because 2005 is not a leap year). If you do
not declare the parameter, and the user enters:
12/2/2005
will that be interpreted as Dec 2 or 12 Feb?
What about:
13/2/2005
Are you surprised at the difference between the last 2 examples?

How about:
29/2
Is that interpreted differently in a leap year than a normal year?
Or is there a chance that might Access interpret that entry as 29 divided by 2 = 14.5, which internally represents the date/time of noon on 13 Jan 1900?
There is too much scope for misunderstanding if you leave your parameters
undeclared and untyped.

The issue also arises for calculated fields in your queries. See:
Calculated fields misinterpreted
at:
http://allenbrowne.com/ser-45.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Thank you very much, Allen. That information is very valuable.
I am not sure what parameters are. A few weeks ago I start building

queries
by hand (in sql mode) and I defined parameters in the first line. And I
added those parameters in the where condition. But when I learnt to create queries in the design mode, I noticed the parameters in the first line
weren't present anymore. What is the point of defining parameters, when I can write straight in the Where conditon, like:
Where (tbTable.Field1 = Forms!MyForm!txtBox)
?

And I am not sure, but it seems that because of the first line, where I
defined parameters, I couldn't export the query to a mailmerge. Once we
removed the parameters line, we could create the mailmerge documents... (I am not 100% sure, have to test more)
Regards,
Nicolae


Nov 13 '05 #7
Thank you again, Allen. It is obvious about the advantages of declaring the
parameters. I've been criticised for typing the queries by hand and
declaring the parameters, but in the end it isn't that bad. Anyway, it is a
lot easier to use the query builder which comes with Access, but at least I
can declare the parameters after I have the query working

Regards,
Nicolae
Nov 13 '05 #8

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

Similar topics

6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
3
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is...
24
by: clare at snyder.on.ca | last post by:
I have a SQL query I need to design to select name and email addresses for policies that are due and not renewed in a given time period. The problem is, the database keeps the information for every...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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,...
0
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...
0
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...

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.