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

generate age

DP
hi,

i've got a customer table, with a date of birth field in it. its entered
like; 12/12/1992

how would i generate an age through this field.

e.g. i've got txtAge.

how would i have the correct age inserted in there?

thanx

dev
Jan 22 '06 #1
7 1755
I would try
=DateDiff("d",[txtBirth],Now())/365

as the control source in field txtAge.

This assumes the DOB field is called "txtBirth" on the form.

This calculates age from TODAY's date, using 365 days per year.

Sara

Jan 22 '06 #2
"DP" <DP@hotmail.com> wrote in message
news:D6*****************@newsfe6-gui.ntli.net...
hi,

i've got a customer table, with a date of birth field in it. its entered
like; 12/12/1992

how would i generate an age through this field.

e.g. i've got txtAge.

how would i have the correct age inserted in there?

thanx

dev


cut and paste the function into a new module. Then you could call it by
setting the control source of a textbox to
=GetAge([MyDateOfBirthField])

Public Function GetAge(BirthDate As Variant) As String

On Error GoTo Err_Handler

Dim dteDOB As Date
Dim lngDays As Long
Dim lngMonths As Long
Dim lngYears As Long
Dim strAge As String

strAge = "Error!"

If Not IsNull(BirthDate) Then

dteDOB = CDate(BirthDate)
lngMonths = DateDiff("m", dteDOB, Date)
lngDays = DateDiff("d", DateAdd("m", lngMonths, dteDOB), Date)
If lngDays < 0 Then
lngMonths = lngMonths - 1
lngDays = DateDiff("d", DateAdd("m", lngMonths, dteDOB), Date)
End If
lngYears = lngMonths \ 12
lngMonths = lngMonths Mod 12

strAge = CStr(lngYears) & " yrs " & _
CStr(lngMonths) & " mths " & _
CStr(lngDays) & " days "

Else
strAge = "Unknown"
End If

Exit_Handler:
GetAge = strAge
Exit Function

Err_Handler:
Resume Exit_Handler

End Function
Jan 22 '06 #3
Go to
http://groups.google.ca/group/comp.databases.ms-access
In the box in the upper right hand corner type
Calculate Age
Click the button "Search This Group"
Read the messages that come up until you find one that gives
information that meets your needs.
You may find out how to calculate age.
You may find out how to get answers to many questions, not just from
those who might read your question today, but from years of reponses to
similar questions.

Jan 22 '06 #4

"DP" <DP@hotmail.com> wrote in message
news:D6*****************@newsfe6-gui.ntli.net...
hi,

i've got a customer table, with a date of birth field in it. its entered
like; 12/12/1992

how would i generate an age through this field.

e.g. i've got txtAge.

how would i have the correct age inserted in there?

thanx

dev

Dev, a quick clarification here. Several others have offered ideas how to
calculate age. Do not store the age in a table! When you need to show the
age in a form or report, use a query to compute the current age. It will
always be based on the difference between DOB and the current Date.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.

Jan 22 '06 #5
I think for speed here I'd make a Table of the first, say, 50000 dates
after 1880. Then I'd create a one way self joining linking table
mapping the table to itself, (1 250 025 000 records) and add three
fields: years, months, days. Then I'd use whatever function I wanted
for age and fill that table with the appropriate age value, eg, the
first record in the table would show (1,1,0,0,0) ... (1,2,0,0,1). Then,
of course, I do my query with a JOIN on the two fields.

Jan 23 '06 #6
DP
hi,

i tried this, and the field sis just blank!.

dev

"sara" <sa*******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I would try
=DateDiff("d",[txtBirth],Now())/365

as the control source in field txtAge.

This assumes the DOB field is called "txtBirth" on the form.

This calculates age from TODAY's date, using 365 days per year.

Sara

Jan 23 '06 #7
DP
i'v done it now.

thanx

dev

"DP" <DP@hotmail.com> wrote in message
news:xP****************@newsfe3-win.ntli.net...
hi,

i tried this, and the field sis just blank!.

dev

"sara" <sa*******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I would try
=DateDiff("d",[txtBirth],Now())/365

as the control source in field txtAge.

This assumes the DOB field is called "txtBirth" on the form.

This calculates age from TODAY's date, using 365 days per year.

Sara


Jan 23 '06 #8

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

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
3
by: Garry Dawkins | last post by:
Hey Frank, I'm a novice with this taking over someone elses application. I'm attempting to add a dataset to a page. I have the query to populate the page and I have the walkthrough instructions. ...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
9
by: Henk Verhoeven | last post by:
We are not alone! "Where other MDA tools are generating programmingcode, Codeless chooses not to generate code at all". OK, phpPeanuts is not an MDA tool (it has no fancy modeling GUI). But it...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
5
by: pete | last post by:
Help, I can not find this data wizard in my toolbox under data. To generate a dataset 1.. From the Data menu, choose Generate DataSet. Tip If you do not see the Data menu, click in the...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
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: 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...

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.