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

linking the date of birth and age in access

2
I just wanted to know in access how you can link the date of brith and age so that when you enter their birthday it automatically updates their age?
Oct 25 '07 #1
3 3326
missinglinq
3,532 Expert 2GB
To get Access to fill in the current age when you enter the Date of Birth, assuming the birth date box is called DOB and the current age box is called CurrentAge:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_AfterUpdate()
  2.   Me.CurrentAge = DateDiff("yyyy", Me.DOB, Date) - IIf(Format$(Date, "mmdd") < Format$(Me.DOB, "mmdd"), 1, 0)
  3. End Sub
If you also want the current age to be updated as time goes by:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me.CurrentAge = DateDiff("yyyy", Me.DOB, Date) - IIf(Format$(Date, "mmdd") < Format$(Me.DOB, "mmdd"), 1, 0)
  3. End Sub
  4.  
Welcome to TheScripts!

Linq ;0)>
Oct 26 '07 #2
kerij
2
To get Access to fill in the current age when you enter the Date of Birth, assuming the birth date box is called DOB and the current age box is called CurrentAge:

Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_AfterUpdate()
  2.   Me.CurrentAge = DateDiff("yyyy", Me.DOB, Date) - IIf(Format$(Date, "mmdd") < Format$(Me.DOB, "mmdd"), 1, 0)
  3. End Sub
If you also want the current age to be updated as time goes by:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me.CurrentAge = DateDiff("yyyy", Me.DOB, Date) - IIf(Format$(Date, "mmdd") < Format$(Me.DOB, "mmdd"), 1, 0)
  3. End Sub
  4.  
Welcome to TheScripts!

Linq ;0)>
Thanks, but where do i put the code...i have already made a table, query and form...(i do want the current age to be updated as time goes by)

Thanks,
Keri
Oct 26 '07 #3
Jim Doherty
897 Expert 512MB
Thanks, but where do i put the code...i have already made a table, query and form...(i do want the current age to be updated as time goes by)

Thanks,
Keri
Hi Keri,

As an extra snippet

You may have a reason for storing date of birth and a statically stored age as separate fields in your database table for some specific reason of course, but just in case you were 'not' aware if it is not actually necessary for you to do that, you can calculate the age based on the date of birth of the person concerned, compared to now. If this is relevant to your circumstances then paste the following into a new MODULE below the line that says 'Option Compare Database' and then save the module as bas_MyModule. You will then be able to use this function anywhere in your database to calculate the number of years since a given date and now.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function Age(Bdate, DateToday) As Integer
  3. On Error Resume Next
  4. If Month(DateToday) < Month(Bdate) Or (Month(DateToday) = Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
  5.     Age = Year(DateToday) - Year(Bdate) - 1
  6. Else
  7. Age = Year(DateToday) - Year(Bdate)
  8. End If
  9.     Resume Exit_Age
  10. End Function
  11.  
You can then reference this function in your query to calculate the age of the person concerned. The function will look at the date of birth of the person as it is 'sitting' in the queried row and reproduce a column with the age 'calculated' thus updating automatically as time goes by which is what I believe you 'might' be meaning here. If not then obviously disregard me.

Type this into the field section of the query grid. you might want to place it next to your date of birth field for easy viewing. Obviously change DateOfBirth to whatever you have called your date of birth field.

Age: Age([DateOfBirth],Now())

Regards

Jim :)
Oct 27 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Gav | last post by:
I have a database with date of births stored dd/mm/yyyy (english dating system) and =date() returns a date in the same format in my server. how do i find the persons age using these two pieces of...
16
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables...
3
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not...
2
by: TheTamdino | last post by:
One of the things that is common between most genealogy databases is that they will have one screen were you log all the information for a given person and then (maybe) have a link to a source...
4
by: wil | last post by:
Dear All, In the linux platform, is there anyway I can in a C program change the file create date? Thanks, wil.
11
by: tlyczko | last post by:
Hello, I'm new to SQL Server, working for a non-profit computerizing a lot of its data. I imported a table of people's names, birth dates, etc. into SS2005 from Access, and the birth_date was...
2
by: Matuag | last post by:
Hi All, I am trying to create a form which can calculate with Age and Birth Date fields. I want Age to be calculated based on Birth Date (which I managed to do) but at the same time if Birth...
3
by: jamieharrop | last post by:
Afternoon all, I've been battling with this all day today and my brain is now pretty much fried. I have one table that lists several details about my customers (name, address, phone, date of...
1
by: karimufeed | last post by:
I am working on an access project for pension calculation. I want to generate the retirement date automatically at the age of 60 years while filling the date of Birth. i.e. if the Date of birth is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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...

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.