473,386 Members | 1,720 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,386 software developers and data experts.

How to compute age in a query?

I'm looking for an example of how to compute an age of a record in a
query and then display that on a form. For example: I have record
that shows it was entered on 8/2/2005. I would like to be able to have
the query return something like "record is 35 days old".

I know I can compute the age via the DateDiff function in VBA but can't
seem to figure out how to change the value in an unbound control on the
form as I scroll through the recordset.

Any suggestions, comments, code-snippets, etc would be appreciated.

Bill W

Nov 13 '05 #1
1 5538
You can computer the age in a query by creating a calculated field that
calls a user defined function then on the form, bind the textbox to this
field. You can create a calculated control on the form that does the same
thing. It should then recalculate as you go to each record.

In the query, the field would look like:
RecordAge:MyFunction([RecordDateField])

In the form, the textbox's Control Source would be like:
=MyFunction([txtRecordDateTextbox])

For examples for the user defined function, follow this link:
http://www.mvps.org/access/datetime/date0001.htm

You may need to adjust this for the format that you want the result in. If
all you're wanting is a few days at most, then DateDiff() by itself is
probably sufficient and you could skip the user defined function.

Example:
RecordAge:DateDiff("d", [RecordDateField], Date())
or
=DateDiff("d", [txtRecordDateTextbox], Date())

--
Wayne Morgan
MS Access MVP
"wildbill" <we*******@charter.net> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I'm looking for an example of how to compute an age of a record in a
query and then display that on a form. For example: I have record
that shows it was entered on 8/2/2005. I would like to be able to have
the query return something like "record is 35 days old".

I know I can compute the age via the DateDiff function in VBA but can't
seem to figure out how to change the value in an unbound control on the
form as I scroll through the recordset.

Any suggestions, comments, code-snippets, etc would be appreciated.

Bill W

Nov 13 '05 #2

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

Similar topics

1
by: pentium77 | last post by:
Hi, Just wondering what's the algo used to compute hashcode in Java ? Does anybody here know ? Thanks, -MK.
1
by: rock72 | last post by:
I am developing a application using this fields as required by the company. 1. Date Login 2. Time IN 3. Time OUT My question is how to produce the number of days with 1 entry of Date is...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
1
by: skirkby | last post by:
This will be obvious to some - but not me I'm afraid... I am using an SQL data link from my ASP application to a SPROC - this all works fine on standard SELECT statements and JOIN in to a...
2
by: Maciej Bliziński | last post by:
Hello, I started to write the query that should compute the median. Surprisingly, I get following error message: "server closed the connection unexpectedly This probably means the server...
6
by: Spoon | last post by:
Hello, Consider: #define BUFFER_SIZE 1234 /* or some other value */ uint8_t buffer; int do_stuff(uint8_t *buf); where do_stuff() does something with each octet in the buffer.
0
by: billyssmail | last post by:
Can i Use SQL COMPUTE clause in an ASP recordset query ?? if yes, how i will reterive / display recordset values in ASP application thanks in advance
2
gchq
by: gchq | last post by:
Hi there I am attempting to compute some values from a DataTable. It works fine as long as there is a value to retrieve, otherwise it blows out! This will work as there are valid dates:- ...
1
by: nbharatha | last post by:
Hi, Environment: Only one database per instance however each application is given it's own schema. My objective is to compute the space utilized by each application on the DB2 Database....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.